-->
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: isNotEmpty and Inheritance with table per class hierarchy
PostPosted: Fri Nov 10, 2006 4:54 am 
Newbie

Joined: Fri Nov 10, 2006 4:24 am
Posts: 1
Hello,

I have a little problem using the isEmpty() restriction of the criteria api. Maybe anybody can help.

Hibernate version:

3.2.0 but could also be reproduce the issue with 3.1.3

Mapping documents:

Lets say there are three fruit classes like this:

Code:
<class name="Fruit" table="FRUIT">

    [...]

  <many-to-one name="basket"
    class="FruitBasket"
    column="BASKET_ID"
    cascade="none"
    not-null="true"
    update="false"
    lazy="false"
    fetch="join"/>

  <subclass name="Apple" discriminator-value="apple">
    [...]
  </subclass>

  <subclass name="Pear" discriminator-value="pear">
    [...]
  </subclass>

  <subclass name="Plum" discriminator-value="plum">
    [...]
  </subclass>

</class>


Then we have a FruitBasket class:

Code:
<class name="FruitBasket" table="FRUIT_BASKET">

  [...]

  <set name="apples" inverse="true" cascade="none" lazy="true" where="TYPE='apple'">
    <key column="BASKET_ID"/>
    <one-to-many class="Apple"/>
  </set>

  <set name="pears" inverse="true" cascade="none" lazy="true" where="TYPE='pear'">
    <key column="BASKET_ID"/>
    <one-to-many class="Pear"/>
  </set>

  <set name="plums" inverse="true" cascade="none" lazy="true" where="TYPE='plum'">
    <key column="BASKET_ID"/>
    <one-to-many class="Plum"/>
  </set>

</class>


Code between sessionFactory.openSession() and session.close():

What I want to do now is a criteria query like this:

Code:
List list = session.createCriteria(FruitBasket.class).add( Restrictions.isNotEmpty("pears") ).list;


So I want to get all fruit baskets that have pears in them.

The generated SQL (show_sql=true):

That is the problem. What Hibernate generates is a clause like this:

Code:
...where exists (select 1 from FRUIT where this_.ID=BASKET_ID)


So I am not only getting the fruit baskets with pears, but all that have any fruit at all in them. Since the arbitrary sql where condition from my FruitBasket Mapping document is ignored it does not really matter if the isNotEmpty restriction is true for the pears collection. I am getting all Objects where the isNotEmpty restriction is true for any of the tree collections (apples, pears and plums).

Name and version of the database you are using:

PostgreSQL 7 if it does matters.


Any suggestions? Of course I can work my way arround it somehow, but it would be much nicer working with the isNotEmpty restriction. Could this be a bug in Hibernate or am I doing something wrong?

Thanks for your help
Axel


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.