-->
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.  [ 7 posts ] 
Author Message
 Post subject: how to re-attach collection with session (evicted problem)
PostPosted: Thu Sep 29, 2005 5:11 am 
Senior
Senior

Joined: Mon Aug 22, 2005 5:45 am
Posts: 146
We still got the problem with detached collection-proxies that won't lazy load.

When we trigger lazy-loading a collection this is what we basically do to init the collection:

collProxy.setCurrentSession(Util.createSession()); // attach new session, because original session is lost
collProxy.forceInitialization(); // init

Unfortunately this results in a HibernateException: "collection was evicted"

How can we prevent this error?



Hibernate version: 3.0.5


Top
 Profile  
 
 Post subject: seems like a hack, is there a better way?
PostPosted: Mon Oct 03, 2005 4:46 pm 
Beginner
Beginner

Joined: Thu Dec 09, 2004 7:04 pm
Posts: 26
Location: Denver, CO
This seems like you are fighting the Hibernate management of objects.

So lets start at the top: Why are you trying to lazy load a collection after you has disconnected it?

Based on that reply, there are some options:

1.) Don't disconnect the object, use a managed session object (currentSession() rather than openSession).

2.) Apply a filter that closes the session later so you can use the session while running a JSP.

3.) Open a new session and attach the object using the public API to the new session.

Better options given with better information.


Top
 Profile  
 
 Post subject: Re: seems like a hack, is there a better way?
PostPosted: Tue Oct 04, 2005 3:24 am 
Senior
Senior

Joined: Mon Aug 22, 2005 5:45 am
Posts: 146
jliptak wrote:
So lets start at the top: Why are you trying to lazy load a collection after you has disconnected it?


The reason is because we are sending the objects over RMI to a swing client, and the session-instance of the pojo-proxy is lost. Therefore when we call person.getAdresses() the session-instance of the adresses-collection-proxy is lost. I think this is quite common issue.

What would you suggest to do?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 4:00 am 
Newbie

Joined: Sat Jul 23, 2005 8:31 am
Posts: 18
i would create proxies for the proxies. it's probably quite easy to create them automatically from the hibernate mapping file with a dom parser and a template engine.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 4:04 am 
Senior
Senior

Joined: Mon Aug 22, 2005 5:45 am
Posts: 146
create proxies for the proxies? Could you explain this concept in more detail, pls.
And what exactly do you want to parse, and why do you need a template engine...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 5:01 am 
Newbie

Joined: Sat Jul 23, 2005 8:31 am
Posts: 18
Quote:
i would create proxies for the proxies


i imagine that it must be quite complex to use hibernate via RMI and that there will be lots of problems. to avoid the problems i wouldn't access the hibernate objects directly via RMI from the client side. i would implement an RMI layer which gets the informations for the client side from hibernate but wouldn't expose the hibernate objects directly to the client.

but i must say myself that it might not be as easy as i first tought.


Quote:
it's probably quite easy to create them automatically from the hibernate mapping file with a dom parser and a template engine.


here i just meant that the RMI layer can be generated automatically. but to be sure about this i would have to invest some time to check it out.



it also can be that this is a quite stupid solution, i don't know hibernate nor RMI very well.


Top
 Profile  
 
 Post subject: Re: seems like a hack, is there a better way?
PostPosted: Tue Oct 04, 2005 10:15 am 
Beginner
Beginner

Joined: Thu Dec 09, 2004 7:04 pm
Posts: 26
Location: Denver, CO
axismundi wrote:
jliptak wrote:
So lets start at the top: Why are you trying to lazy load a collection after you has disconnected it?


The reason is because we are sending the objects over RMI to a swing client, and the session-instance of the pojo-proxy is lost. Therefore when we call person.getAdresses() the session-instance of the adresses-collection-proxy is lost. I think this is quite common issue.

What would you suggest to do?


So based on the code, you seem to be creating a hibernate session on the swing client and then you are trying to re-connect the objects there. If that's the case, why don't you just pass the key's of the objects around and load everything on the swing client?

What you are probably trying to do, is to have the RMI stubs provide you the data from the server. If so, your code does not really match what you are trying to do. What you need is a container for your session that matches the length of time your RMI calls are active. So if you have code such as:
Code:
//server
public daoX getData() {
  Session session = openSession();
  // get data with lazy
  session.close();
}

It's not going to work.

You need something more like a CORBA servant. You would have your swing clients create a rmi session object that contains your hibernate session. All calls to get data would go through that session object so that lazy loading would work. You would also need some kind of ping protocol so that the session objects would get cleaned up if the swing client goes away.

As another poster suggested, you could use your mapping files to generate the code necessary to have your object walking functions put into the servant object.[/code]


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