-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Restrict many-to-many with where
PostPosted: Tue Mar 30, 2010 7:01 am 
Newbie

Joined: Tue Mar 30, 2010 6:32 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.