wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Why update() is necessary? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Why update() is necessary?" Watch "Why update() is necessary?" New topic
Author

Why update() is necessary?

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Hi.
If we have a detached object and want to reconnect it to Session, we call update() method.
But really, why this is necessary? I mean what happens under the hood?
Thanks.
Walter Bernstein
Ranch Hand

Joined: Dec 19, 2007
Posts: 57
"What happens under the hood?"

=> your object gets reconnected/attached to the current hibernate session.
=> at some point hibernate tries to update your object in the db.

I prefer session.lock() to reconnect a object.
Walter Bernstein
Ranch Hand

Joined: Dec 19, 2007
Posts: 57
"But really, why this is necessary?"

=> If an object is not connected to a hibernate session, it is not managed by hibernate. So any change to your object will not be persisted.
[ December 26, 2007: Message edited by: Walter Bernstein ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why update() is necessary?