Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: StatelessSession and eager fetching
PostPosted: Mon Jan 09, 2006 8:51 pm 
Regular
Regular

Joined: Fri Mar 26, 2004 11:45 am
Posts: 75
I just started using StatelessSessions in Hibernate 3.1 and immediately ran into problems with non-lazy entities. What I am trying to do is run a simple Criteria query on a table, which mapping has lazy="false".

The query retrieves all the rows from the table and I print them out as they are being retrieved. This process crashes all the time if lazy property of the table mapping is set to false. The exception thrown is listed below. If I change lazy="true", then the query work fine.

Existing code depends on the mapping being non-lazy, so I'd prefer not to change it in the mapping file. Is there a way to change the "lazy" property of a mapping at runtime?

Note that I need to print out the content of the entire table in a file. The table content is way too large to fit in main memory. Hence, I was using StatelessSessions to reduce memory overhead.

Is there any other solution for this problem?

Here is the exception that gets thrown when traversing the Criteria query with StatelessSession:


3797 ERROR [main] hibernate.AssertionFailure - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: possible non-threadsafe access to the session
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:97)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:93)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
at org.hibernate.impl.StatelessSessionImpl.get(StatelessSessionImpl.java:272)
at org.hibernate.impl.StatelessSessionImpl.get(StatelessSessionImpl.java:268)
at org.hibernate.impl.StatelessSessionImpl.internalLoad(StatelessSessionImpl.java:303)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.loadSingleRow(Loader.java:276)
at org.hibernate.impl.ScrollableResultsImpl.prepareCurrentRow(ScrollableResultsImpl.java:231)
at org.hibernate.impl.ScrollableResultsImpl.next(ScrollableResultsImpl.java:100)
at org.waterford.sm.importExport.ImExBatchTest.processUsingStatelessSessions(ImExBatchTest.java:192)
at org.waterford.sm.importExport.ImExBatchTest.timeTest(ImExBatchTest.java:106)
at org.waterford.sm.importExport.ImExBatchTest.main(ImExBatchTest.java:228)
org.hibernate.AssertionFailure: possible non-threadsafe access to the session
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:97)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:93)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
at org.hibernate.impl.StatelessSessionImpl.get(StatelessSessionImpl.java:272)
at org.hibernate.impl.StatelessSessionImpl.get(StatelessSessionImpl.java:268)
at org.hibernate.impl.StatelessSessionImpl.internalLoad(StatelessSessionImpl.java:303)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.loadSingleRow(Loader.java:276)
at org.hibernate.impl.ScrollableResultsImpl.prepareCurrentRow(ScrollableResultsImpl.java:231)
at org.hibernate.impl.ScrollableResultsImpl.next(ScrollableResultsImpl.java:100)
at org.waterford.sm.importExport.ImExBatchTest.processUsingStatelessSessions(ImExBatchTest.java:192)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 11, 2006 4:01 am 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
try using a ThreadLocal session instance

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 11, 2006 12:21 pm 
Regular
Regular

Joined: Fri Mar 26, 2004 11:45 am
Posts: 75
There is only one thread in my application, so using ThreadLocal is not needed. I just have a main method, which tries to retrieve all the rows from a table via StatelessSession and it crashes all the time.

Any other thoughts?


Top
 Profile  
 
 Post subject: Re: StatelessSession and eager fetching
PostPosted: Wed May 31, 2006 3:23 pm 
Newbie

Joined: Fri Apr 15, 2005 7:52 pm
Posts: 13
Unfortunately this has nothing to do with whether the session is thread local or not. You can look at this thread for crossreference:

http://forum.hibernate.org/viewtopic.ph ... 43#2306043

However, noone has replied yet although there are at least 3 threads out there describing the same problem. It would be cool to get any feedback, be it a user error or a bug that is being worked on. I guess you could patch the sources yourself for now by checking for stateless sessions and switching too lazy fetching on those and work with your patched version until this gets resolved.

_________________
Tired of spam? => http://www.spamino.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 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.