-->
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: multiple instances of same bean
PostPosted: Mon Jun 07, 2010 7:56 am 
Newbie

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

Suppose i have 2 classes
Person and Car

and the person has a list of children
and the car has list of owners

one of those persons children can be the same as an owner of a car

if I do this in Hibernate I indeed get the same child/owner from the DB, but they are different instances in java. With this i mean that if i change a property of the child then the owner list is not changed, because they are different instances. What I would like to do is make sure that trough pointers the same rows in a DB represent also the same object in java, so if one changes the other one gets update automatically trought pointers.

I hope you understand what i mean...

thanks for the help


Top
 Profile  
 
 Post subject: Re: multiple instances of same bean
PostPosted: Mon Jun 07, 2010 8:19 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
if I do this in Hibernate I indeed get the same child/owner from the DB, but they are different instances in java. With this i mean that if i change a property of the child then the owner list is not changed, because they are different instances. What I would like to do is make sure that trough pointers the same rows in a DB represent also the same object in java, so if one changes the other one gets update automatically trought pointers.


Have you really verified that this is the case? One very fundamental aspect of Hibernate is that within a single Hibernate session a given row is represented by a single object instance. Due to proxies you may (in rare cases) see multiple instances in your code but all point to the same underlying "real" instance and changes made are immediately visible by all other proxies.

The above is true for work done in a single Hibernate session. If you start mixing objects loaded with different session it is a different matter and it is your own responsibility to handle.

There is a short note in the documentation about this: http://docs.jboss.org/hibernate/stable/ ... s-identity


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