-->
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.  [ 4 posts ] 
Author Message
 Post subject: managing detached beans retrieved in multiple sessions.
PostPosted: Thu Jun 24, 2010 11:49 am 
Newbie

Joined: Mon Jun 07, 2010 7:50 am
Posts: 8
Hello

Suppose I have class Parent and a class Child

Code:
public class Parent {

   ArrayList<Child> children;

}

class Child {

Parent p;

}   


First I retrieve a Parent from the database with all its children.
I close my session, so now I have 1 Parent with all its children as detached objects.

I now start a second session and only retrieve 1 child. But that child's parent is the same parent I retrived from the first session. So that child is also in the list of children I got from my first DB transaction.

But the problem is: they are both different java instances. So if I change the parent object I got from the first transaction, or I change the child from the second transaction, then I have 2 objects that represent the same row in DB but with different values.

Is there a way to solve/manage these kind of things?

thank you


Top
 Profile  
 
 Post subject: Re: managing detached beans retrieved in multiple sessions.
PostPosted: Thu Jun 24, 2010 12:21 pm 
Beginner
Beginner

Joined: Fri May 18, 2007 10:28 am
Posts: 48
Location: Madison, WI
If you are having two copies of the same data, it is better to go back to your design and see how best you can re-use the data instead of making two DB calls.

_________________
Please rate if it helped


Top
 Profile  
 
 Post subject: Re: managing detached beans retrieved in multiple sessions.
PostPosted: Thu Jun 24, 2010 4:06 pm 
Newbie

Joined: Mon Jun 07, 2010 7:50 am
Posts: 8
thank you for the reply, but I can imagine that that's not always possible

suppose if my second object(Child) that represents data I allready have somewhere in my application was fetched with a query that retrieved ALL Child objects from the DB? So suppose I wanted to retrieve all Child objects from the DB, should I then first check which ones I allready have in my application? and only query the rest of the Child objects? And if yes, what if some properties of child were not loaded on the first time I got my Child object from the DB?

I hope you can still follow me, this thing is bothering me for quite some time now...


Top
 Profile  
 
 Post subject: Re: managing detached beans retrieved in multiple sessions.
PostPosted: Thu Jun 24, 2010 4:49 pm 
Newbie

Joined: Wed Jan 30, 2008 6:40 pm
Posts: 3
hi berndvv

that case is like thread environment? one thread changes one child, second thread makes another changes

both threads have different objects but this objects are same db record, i got it??

now your question is how sync both objects to the database record?

well i read about hibernate caching and concurrence in book Java Persistence (long time ago, sorry) maybe u need read about this topic

regards

Grubhart


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