-->
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.  [ 6 posts ] 
Author Message
 Post subject: LazyInitializer error
PostPosted: Sat Oct 18, 2003 2:55 pm 
Newbie

Joined: Mon Oct 06, 2003 4:41 pm
Posts: 18
I'm using the Open Session in View pattern and I get the following stacktrace in multi-user situations on a relatively long-lived request. I.e. it only occurs when multiple users are make requests at similar times.

My code currently doesn't implement any transaction support at all which I suspect is the cause of the error but I'd appreciate it anyone could confirm this.

Thanks,
Matt.

Code:
net.sf.hibernate.LazyInitializationException: Illegally attempted to associate a proxy with two open Sessions
        at net.sf.hibernate.proxy.LazyInitializer.setSession(LazyInitializer.java:144)
        at net.sf.hibernate.impl.SessionImpl.reassociateProxy(SessionImpl.java:883)
        at net.sf.hibernate.impl.SessionImpl.unproxyAndReassociate(SessionImpl.java:867)
        at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1259)
...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 18, 2003 3:27 pm 
Newbie

Joined: Mon Oct 06, 2003 4:41 pm
Posts: 18
Having read section 11.1 of the documentation again is it more likely that this error is being caused by using the class itself as the lazy initialization proxy? I'll try seperating out and using the interface instead...

Matt.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 19, 2003 12:42 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Looks like your are trying to persist the same java instance into 2 differents sessions. It isn't allowed.

Code:
myObject  = session1.load();
session2.saveOrUpdate(myObject);

It's certainly more complex than that in your case.

You can evict the object before associating it to a second session
Code:
myObject  = session1.load();
session1.evict(myObject);
session2.save(myObject);


But the best solution is not you be in such a case. Are you sharing java instance taken from session1 (still opened) and using it with a second session ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 19, 2003 1:27 pm 
Newbie

Joined: Mon Oct 06, 2003 4:41 pm
Posts: 18
epbernard wrote:
Are you sharing java instance taken from session1 (still opened) and using it with a second session ?


I shouldn't be, I'm using the open session in view pattern so if my understanding is correct then each request will get a new Session instance and I'm using each session to load and save my POJOs. I guess with no transactions enabled then this is asking for trouble in a multi-user scenario. I'll let you know what happens when I start wrapping the operations in transactions.

Matt.


Top
 Profile  
 
 Post subject: webapp pitfalls
PostPosted: Mon Oct 20, 2003 11:51 am 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
Are you sure you aren't storing any persistent instance on the servlet session or application contexts, a static context, or another thread? (I'm assuming you are using Tomcat or something similar.) Session in view can cause problems if your persistent instances can exist between views, ie between HTTP requests.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 7:21 pm 
Newbie

Joined: Mon Oct 06, 2003 4:41 pm
Posts: 18
My apologies for wasting anyone's time and thanks for the help. After a fair amount of exploring I realised I was storing a reference to the Session as an instance variable in the base class for my struts actions, i.e. it wasn't threadsafe. Very stupid.

Matt.


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