-->
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.  [ 2 posts ] 
Author Message
 Post subject: readOnly transaction leads to LazyInitializationException
PostPosted: Wed Oct 10, 2012 1:40 am 
Newbie

Joined: Thu Sep 30, 2010 5:32 am
Posts: 4
Please refer to following post on SO:

http://stackoverflow.com/questions/12800531/transactionalreadonly-true-leads-to-lazyinitializationexception

I thought maybe some people here know more about this issue. Currently I'm pretty certain is a bug.

As summary of the SO thread:

Changing a transaction to readOnly (eg. annotate method with @Transactional(readOnly = true)) leads to LazyInitializationException even though the affected relations are fetch eager (eg. FetchType.EAGER). If the method is just annotated with @Transactional, it works perfectly fine.

In the log you can clearly see that hibernate is not doing the same thing and with readOnly = true log is much shorter and the parts were the relatated entites are fecthed is missing, eg. less SQL statements are issued (which of course explains why LazyInitializationException) but it does not explain why does entities are fetched lazy.

Anyone else had this issue? Solution?


Top
 Profile  
 
 Post subject: Re: readOnly transaction leads to LazyInitializationException
PostPosted: Fri Oct 12, 2012 4:05 am 
Beginner
Beginner

Joined: Fri Jul 20, 2007 10:38 am
Posts: 49
I've had some weird experiences like that too, for me, I've 'solved' it by EAGER loading the collection, using the javax.persistence annotations for OneToMany and org.hibernate.annotations CascadeType ALL in a separate tag (not inside the @OneToMany).
I don't know if it'll work for you though. I'm using 3.6.9.Final btw.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.