File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Why update() is necessary?" Watch "Why update() is necessary?" New topic

Why update() is necessary?

Hussein Baghdadi
clojure forum advocate

Joined: Nov 08, 2003
Posts: 3479

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?
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 ]
I agree. Here's the link:
subject: Why update() is necessary?
It's not a secret anymore!