-->
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.  [ 3 posts ] 
Author Message
 Post subject: loading one-to-many relationship using stored procedure
PostPosted: Mon May 16, 2005 3:23 am 
Newbie

Joined: Wed Apr 13, 2005 7:32 pm
Posts: 11
Gidday,

I'm using stored procedures to load data and have been trying to setup a one-to-many relationship between to classes. I have 2 classes that I can individually load successfully via stored procedures but when I try and use the Set element to to define a one-to-many relationship between the resultsets of ClassA and ClassB, I get an exception - invalid object name ClassB.

<class name="ClassA">

definition omitted

<set name="classBSet" lazy="false" >
<key>
<column name="Col1" />
<column name="Col2" />
<column name="Col3" />
<column name="Col4" />
</key>
<one-to-many class="ClassB" />
</set>

definition omitted

</class>

It would appear that Hibernate doesn't lookup the mapping file for ClassB when loading this relationship but instead constructs a query to select data from a table called ClassB.

Is there a setting/attribute/element that I can use to tell Hibernate to use the mapping file to to load this relationship?

If not, then any suggestions/pointers on a way to implement this would also be great.

Cheers,
Dan.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 3:45 am 
Newbie

Joined: Wed Apr 13, 2005 7:32 pm
Posts: 11
Well I guess it sometimes takes posting to a forum to help you solve a problem (kind of like walking over to another programmer and realising you know the answer just after asking a question).

Anyway, I used the <loader /> element to execute the stored procedure (eg. <loader query-ref="findClassBs" />).

Have another problem now :-/

Onwards and upwards a I guess.

Cheers,
Dan.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 7:12 am 
Newbie

Joined: Wed Apr 13, 2005 7:32 pm
Posts: 11
okay,

now that I'm using <loader /> if get a NullPointerException (Stack trace shown below).

It would appear that the code is looking for a Role (java.lang.String) on the class org.hibernate.engine.CollectionKey.

I was also reading in the Hibernate manual that:

Quote:
Notice stored procedures currently only return scalars and entities. <return-join> and <load-collection> are not supported.


Does this have anything to do with the problem I'm experiencing?

Cheers,
Dan.

java.lang.NullPointerException
at org.hibernate.engine.CollectionKey.<init>(CollectionKey.java:29)
at org.hibernate.engine.CollectionLoadContext.getLoadingCollection(CollectionLoadContext.java:65)
at org.hibernate.loader.Loader.handleEmptyCollections(Loader.java:690)
at org.hibernate.loader.Loader.doQuery(Loader.java:384)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:210)
at org.hibernate.loader.Loader.doList(Loader.java:1562)
at org.hibernate.loader.Loader.list(Loader.java:1545)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1406)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:151)
at org.hibernate.persister.collection.NamedQueryCollectionInitializer.initialize(NamedQueryCollectionInitializer.java:49)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:483)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1422)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:271)
at org.hibernate.engine.PersistenceContext.initializeNonLazyCollections(PersistenceContext.java:796)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:215)
at org.hibernate.loader.Loader.doList(Loader.java:1562)
at org.hibernate.loader.Loader.list(Loader.java:1545)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1406)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:151)
at org.springframework.orm.hibernate3.HibernateTemplate$32.doInHibernate(HibernateTemplate.java:813)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:311)
at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:804)
at com.yoogalu.advert.alam.online.domain.content.home.ALAHeaderHome.find(ALAHeaderHome.java:76)
at com.yoogalu.advert.alam.online.domain.content.home.ALAHeaderHome.findUserALA(ALAHeaderHome.java:40)
at com.yoogalu.advert.alam.online.domain.content.home.ALATest.testRetrieveEntireALA(ALATest.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)

Quote:
Quote:


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

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.