-->
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: criteria.list() is not working properly with "fetch='jo
PostPosted: Thu Sep 21, 2006 1:58 am 
Newbie

Joined: Wed Sep 20, 2006 5:50 am
Posts: 1
Location: bangalore
Hibernate version:Hibernate-3.1.3
Name and version of the database used: Mysql 4.1.15-nt
Database state: UserData table has more number of entries than Users table.

Mapping documents:
Code:
<hibernate-mapping>
<class name="com.test.user.User" table="users" proxy="com.test.user.User">
  <id name="userId" type="java.lang.Integer" column="UserId">
    <generator class="native" />
  </id>
  <set name="userdata" lazy="true" cascade="all" inverse="true" [b]fetch="join"[/b]>
        <key><column name="UserId" /></key>
        <one-to-many class="com.test.user.Userdata"/>
  </set>
</class>

<class name="com.test.user.Userdata" table="userdata" proxy="com.test.user.Userdata">
   <id name="userDataId" type="java.lang.Integer" column="UserDataId">
       <generator class="native" />
   </id>
   <many-to-one name="user" class="com.test.user.User" not-null="true">
        <column name="UserId" />
   </many-to-one>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Case1:
Code:
Criteria criteria = session.createCriteria(User.class);
System.out.println("Total Users:="+criteria.list().size());     

Case2:
Code:
Query queryObject = session.createQuery("from User");       
System.out.println("Total Users:="+queryObject.list().size());

Description of an error:
Ideally, both cases should give same result, but results are not as expected.
    Case 1 Gives total rows in UserData table.
    Case 2 Gives total rows in Users table as expected.

If we remove 'fetch="join"' from mapping, both cases work fine and will give total rows in Users table.


The generated SQL (show_sql=true):
Case 1:
Code:
Hibernate: select this_.UserId as UserId0_1_, userdata2_.UserId as UserId3_, userdata2_.UserDataId as UserDataId3_, userdata2_.UserDataId as UserDataId1_0_, userdata2_.UserId as UserId1_0_ from users this_ left outer join userdata userdata2_ on this_.UserId=userdata2_.UserId

Case 2:
Code:
Hibernate: select user0_.UserId as UserId0_ from users user0_


Can u tell me, why criteria.list() gives wrong result, if fetch="join" is set. Expected result for criteria.list() is size of Users table, and not the size of UserData table.

_________________
Paritosh Chandrapal


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.