-->
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: Changes over-ridden in memory
PostPosted: Mon Sep 24, 2007 1:21 pm 
Senior
Senior

Joined: Mon Jul 24, 2006 8:43 am
Posts: 160
Hi,
When I refresh entities, hibernate by default reads in any M:1 or 1:1 relationships that the entity points to or that point to the entity.
Note: I am not using cascade persist, this is just the default behaviour of hibernate.

I have a 1:1 between Person and Address and both are persistent.
I set a variable on Person and then re-read Address, which will also re-read the Person.
I can see this in SQL generated.
Because person is re-read I would have thought the change in memory would have been overriden but it is not.
In code it is:

Code:
address.setPerson(person);
person.setAddress(person);
person.setFirstName("tony");
entityManager.persist(address);
entityManager.persist(person);
entityManager.getTransaction().begin();
entityManager.getTransaction().commit();
person.setFirstName("adam");
entityManager.refresh(address);
System.out.println("Person name is now..." + address.getPerson().getFirstName());

This outputs:
Person name is now... adam
I would have thought it would have been tony, comments please...

Is there ever a case when something in memory will be overriden?


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.