-->
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: Hibernate incorrectly retaining closed session info
PostPosted: Sun Sep 18, 2005 12:46 am 
Newbie

Joined: Sun Sep 18, 2005 12:26 am
Posts: 4
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed

Using: Hibernate 3.1Beta
JDK: 1.5.0_04

I have a situation where I believe Hibernate is incorrectly retaining infomation for a closed session on objects loaded from new session instances.

I have a replication requirement whereby I have a "master" session, and several "slave" session configurations. At regular intervals, a scheduled task opens the "master" session and gets a list of replication tasks. Each task corresponds to a CREATE, UPDATE or DELETE against a "slave" session. Hence, I need to keep the master session open whilst opening and closing slave session.

The problem manifests in the following situation:

Consider 2 Objects, A and B.
Object A contains an instance of Object B
The replication system needs to update BOTH of these objects, as two separate steps. (That is, update Object A only, then update Object B only; no cascading)

The replication task runs as follows

Using (already opened) master system, load Object A
Evict Object A from master session
Open slave session
Save Object A against slave session
Close slave session

Using (already opened) master system, load Object B
Evict Object B from master session
Open slave session
Save Object B against slave session <-- ERROR HERE
Close slave session

Debugging, it seems the following is occurring:

When Object B is loaded, the nested session inside the org.hibernate.proxy.CGLIBLazyInitializer is the SAME INSTANCE as the session used to load Object A, which was closed.

So, it seems that even though I am closing the session and loading Object B with a newly opened session instance, the LazyInitializer is retaining the information from the earlier session in which Object A was loaded. I can only assume that Object B has this "old" session as the nested session in the CGLIBLazyInitializer because it was once loaded using this session instance when Object A was originally loaded.

Is there a way I can tell Hibernate to completely abandon the older closed session, or alternatively tell it that Object B should disregard it's earlier incarnation and use the current (open) session?

Thanks.


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.