-->
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.  [ 6 posts ] 
Author Message
 Post subject: Evicting After an update causes no update.
PostPosted: Sun Jan 25, 2004 12:51 pm 
Newbie

Joined: Tue Aug 26, 2003 9:52 am
Posts: 15
Hello,

I'm puzzled by the following point :
Evicting an entity after an update but before flushing causes no update at all. Is this by design ? If an update is called the on the entity, to me the entity should be saved no matter what (thus regardless of eviction).

Dept d10 = (Dept) fSession.load(Dept.class, new Integer(10));
d10.setName(d10.getName() + "1");
fSession.update(d10);
fSession.evict(d10);
fSession.flush();
fSession.connection().commit();

Thanks for your insigths.

Alain.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2004 12:58 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Well, evict() removes the object from the Session, thus making it non-transactional. I'd say this is the expected behavior.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2004 1:26 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It's a common case to fush before evicting to prevent update loss.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2004 5:40 pm 
Newbie

Joined: Tue Aug 26, 2003 9:52 am
Posts: 15
Ok thanks for you posts. I see your point, but what I don't get then is the difference between calling an update() or letting automatic persitence do its work. To me, calling evict would unlist an entity for automatic persistence but would not prevent the entity from being updated if update is called.

Thanks.

Alain


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2004 5:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You only need to call update if you have an object modified outside of a session scope. If you have an object attatched to a Session and modify it, it is allways updated by dirty checking.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 6:25 am 
Beginner
Beginner

Joined: Thu Oct 30, 2003 6:29 am
Posts: 30
Location: Germany, KA
AUTO-FLUSH
having modified an object in the session, it will be persisted automatically after session is closed, or flush() is called. You don't need save() or update()

NO AUTOMATIC FLUSHING
modifying an entity won't lead to automatic persistance. only if you call flush() explicitly the changes are written to the db.
If you make changes to an entity, close a session without calling flush(), keep a reference to this object and than open a new session you can persist those changes by calling update(obj); a simple flush() won't persist entity-changes done in a former session.

EVICT()
will abandon all changes to an entity since last flush()


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