-->
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: Unable to load a collection using an eager fetch
PostPosted: Fri Dec 08, 2006 12:43 am 
Newbie

Joined: Mon Jul 10, 2006 1:47 am
Posts: 8
I have a one to many mapping between the CelIdentity (parent) and CatsChannelValues (child). The CatsChannelValues collection is lazily loaded. In the scenario (code snippet given below) I want to load the parent and collection in select. When I do this using this code

Code:
      Session session = HibernateUtil.getSession();
         List results = session.getNamedQuery(loadIdentityWithChannels)
               .setString(0, iname).list();
         return (CelIdentity) results.get(0)

and inspect the returned object it shows me the object (in the debugger as as CelIdentity$$EnhancerByCGLIB$$b0481f36 and all properties as null. And when I try to get the collection through code
Code:
parent.getCatsChannelValueses()
it returns null.

The strange thing is that if I do this load repeatedly in one hibernate session it works couple of times and then fails. However if I colse the session and open a new one it works !!

Hibernate version:
3.0

Mapping documents:
<hibernate-mapping>
<class name="com.celiberate.orm2.CelIdentity" table="CEL_IDENTITY" catalog="celiberate">
<id name="identityId" type="java.lang.Integer">
<column name="IDENTITY_ID" />
<generator class="native" />
</id>
... ...
<set name="catsChannelValueses" inverse="true" cascade="save-update" lazy="true">
<key>
<column name="IDENTITY_ID" not-null="true" />
</key>
<one-to-many class="com.celiberate.orm2.CatsChannelValues" />
</set>
</class>

<query name="loadIdentityWithChannels">
<!-- [CDATA[ from CelIdentity as c left join fetch c.catsChannelValueses where c.iname=? ]]-->
<![CDATA[ from CelIdentity as c left outer join fetch c.catsChannelValueses where c.name=? ]]>
</query>

</hibernate-mapping>

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

Session session = HibernateUtil.getSession();
List results = session.getNamedQuery(loadIdentityWithChannels)
.setString(0, iname).list();
return (CelIdentity) results.get(0)


Full stack trace of any exception that occurs:

java.lang.NullPointerException
at com.celiberate.orm2.CatsStateDAO.findStateMapByOwner(CatsStateDAO.java:95)
at com.celiberate.orm2.IdentityDAO2.updateGroupPrivileges(IdentityDAO2.java:1312)
at com.celiberate.orm2.IdentityDAO2.updatePrivileges(IdentityDAO2.java:808)
at com.celiberate.orm2.test.TempTest.testGetAndUpdatePrivilege_Privileges2(TempTest.java:173)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)



Name and version of the database you are using:

MySQL 5

The generated SQL (show_sql=true):

select celcontrac0_.CONTRACT_ID as CONTRACT1_6_, celcontrac0_.IDENTITY_ID as IDENTITY2_6_, celcontrac0_.REVERSE_CONTRACT as REVERSE3_6_, celcontrac0_.GROUP_ID as GROUP4_6_, celcontrac0_.TYPE as TYPE6_, celcontrac0_.WITH_ID as WITH6_6_, celcontrac0_.VALID_FROM as VALID7_6_, celcontrac0_.VALID_TO as VALID8_6_, celcontrac0_.STATUS as STATUS6_, celcontrac0_.SHARING as SHARING6_, celcontrac0_.INVITATION_MESSAGE as INVITATION11_6_, celcontrac0_.GIVEN_FIRST_NAME as GIVEN12_6_, celcontrac0_.GIVEN_LAST_NAME as GIVEN13_6_, celcontrac0_.GROUP_PRIVILEGES_APPLY as GROUP14_6_, celcontrac0_.GROUP_SHARING_APPLY as GROUP15_6_ from celiberate.CEL_CONTRACT celcontrac0_ where (celcontrac0_.TYPE, celcontrac0_.WITH_ID)=(? , ?) and celcontrac0_.IDENTITY_ID=?


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.