-->
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: General client-/serverhandling with lazy-initialization
PostPosted: Wed Jun 02, 2010 7:24 am 
Newbie

Joined: Tue Jan 15, 2008 6:26 am
Posts: 8
Hi @all,

I currently get the impression, that I have not yet understood one of the key-concepts of Hibernate. Maybe someone can help me out a little bit.

I have the current scenario, that I´m running a client-server-web-application using hibernate 3 together with Spring 2.5. The persistence-context is NOT set to extended.

As usually in client-server-environments, the client asks for an object using a service. Let´s say he asks for a user. An user-entity will be returned using Hibernate. After the user-entity has left the server it will be detached from the hibernate-session, which is okay for me.

Now let´s say I changed something on the user-entityand would like to send the update to the server. When this user-entity is returned to the server again, it is still unmanaged. So far so good.

Now I´m always asking myself how to reattach this entity to the session again. In many of my services I perform some actions on the entity, before I think it is okay to merge the changes to the database. Let´s say the user has a collection of usergroups and I would like to iterate through this collection before. As this entity is unmangaged I get a LazyInitializationException which is totall understandable in this situation, but what can I do in this situation to prevent this Exception?

So I wonder which is the correct way to go now? Do I have to merge the entity as a first step, everytime it is returned to the service? But what, if I realize, that the entity is not as I expect it at a later step in my service? Do I have to roll back the transaction through throwing an Exception to prevent the merge?
I can´t imagine that I would have to fetch the object again in the service and would have to transferr all changes to this object myself, would I?

Furthermore everytime I merge the session, a new object will be returned. So there´s always a difference between the object I received from the client and the object I´m working with and possibly the client´s object does not have the correct data. So to be sure I would always have to refetch the entity after calling the service. But this sounds a bit strange to me and I wonder if this is the way to go.

As I´m probably not the first one using hibernate in a client-server-environment there have to be a lot of solutions around. So maybe someone can tell me, how to proceed in those cases as I´m a little bit los right now.

So I feel that there has to be a very basic concept in hibernate and maybe someone can point me the right directions.

Thank you very much

Thomas


Top
 Profile  
 
 Post subject: Re: General client-/serverhandling with lazy-initialization
PostPosted: Tue Sep 21, 2010 2:37 pm 
Pro
Pro

Joined: Mon Apr 16, 2007 8:10 am
Posts: 246
An answer to this old post would be very interesting indeed.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.