-->
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.  [ 5 posts ] 
Author Message
 Post subject: Refresh appears not to work
PostPosted: Wed Apr 04, 2007 1:19 pm 
Senior
Senior

Joined: Mon Jul 24, 2006 8:43 am
Posts: 160
Hi,
A refresh appears not to work.
Here is my sample code.

Code:
Address address = new Address()
// code to set primary key
// .
// .
address.setCity("NewYork");
mergedAddress = em.merge(address);
address.setCity("London");
em.getTransaction().begin();
//This will commit the merged address
//The city will be set to NewYork as the address object
// is not attatched, when the city is changed to London
em.getTransaction().commit();
em.refresh(mergedAddress);
// This will output NewYork
System.out.println("MergedAddress.City = " + mergedAddress.getCity());

em.refresh(address);
// This will output London
System.out.println("Address.City = " + address.getCity());

The value London is never persisted, I don't know why it is outputted when address is refreshed doesn't make any sense?
Comments appreciated...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 3:06 pm 
Beginner
Beginner

Joined: Sun Nov 16, 2003 3:04 pm
Posts: 24
Try throwing a 'flush()' in there. My guess is that hibernate is caching things and waiting. A flush forces it to send stuff down right then and there...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 12, 2007 4:52 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
your last operation really should raise
IllegalArgumentException( "Entity not managed" );

which version are you using (use the template next time)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 10:54 am 
Senior
Senior

Joined: Mon Jul 24, 2006 8:43 am
Posts: 160
emmanuel wrote:
your last operation really should raise
IllegalArgumentException( "Entity not managed" );

which version are you using (use the template next time)

Apologies:
EntityManager: 3.2.0.CR1
Core: version 3.2 cr2
Annotations: Version: 3.2.0 CR1


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 2:46 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I can't remember for this CR versions, but the stable ones should behave as I said (exception)

_________________
Emmanuel


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