0

There are two entities - A and B.

class A {
public List<B> bAr;
}
class B {
public int count;
}

for hql query like:

select root FROM A root INNER JOIN FETCH root.bAr b WHERE b.count > 0

let's say where are no B rows where count is > 0. By default i get null as result. What i need is to get an object of type A with bAr as an empty collection.

Is it possible to modify this query or set some hibernate configuration option to get needed result?

Oleg Gello
  • 253
  • 1
  • 2
  • 4

1 Answers1

0

When you perform an INNER JOIN, both tables are expected to have rows matching your criteria. If you want to get rows from one table wether there are rows in the other one or not, you need to perform a LEFT JOIN or RIGHT JOIN.

Use this query instead:

select root FROM A root LEFT JOIN FETCH root.bAr b WHERE b.count > 0

You can read more information here:

SQL Joins

Bernat
  • 492
  • 5
  • 13