Hello,
I experience a problem with many-to-many list whose contents I want to filter using a where-clause.
My db-tables look like this:
CONTAINER (UID, ...)
ELEMENT (UID, FILTER_STATE)
CONTAINER_TO_ELEMENT (CONTAINER_UID, ELEMENT_UID, LIST_INDEX)
The goal is to only get the elements of a container that do not have a filter state, i. e. FILTER_STATE is null. My mapping-file therefore contains the following:
Code:
[...]<list name="ContainedElements" table="CONTAINER_TO_ELEMENT" >
<key>
<column name="CONTAINER_UID" />
</key>
<list-index column="LIST_INDEX"/>
<many-to-many class="ELEMENT" where="FILTER_STATE is null">
<column name="ELEMENT_UID" />
</many-to-many>
</list>[...]
For a certain container I have 96 Elements and one of them has a filter state. Therefore I should get a list with 95 elements. When I access the relation, Hibernate uses the following SQL (at least it claims to):
Code:
select [...] from MYDB.CONTAINER_TO_ELEMENT struc0_ left outer join MYDB.ELEMENT element1_ on struc0_.ELEMENT_UID=element1_.uid where ( element1_.FILTER_STATE is null ) and struc0_.CONTAINER_UID=?
If I execute that statement manually I get the expected 95 elements which is exactly what I want. However, Hibernate returns a list with 96 elements where one item in the list is null.
How can I tell Hibernate to give me the result I want, i. e. how can I get rid of the null-entry?
Any help is appreciated.
Best regards,
Jochen
P.S.: I also tried to use a filter but I get the same result.