Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Object Relational Mapping and the fly likes what does hiobernate Session's update work ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "what does hiobernate Session Watch "what does hiobernate Session New topic

what does hiobernate Session's update work ?

Raj Ohadi
Ranch Hand

Joined: Jun 30, 2006
Posts: 316
I am confused how hibernate Session's build-in method update(Object) actually works. Suppose I have a table like

STUDENT(ID, name, address, phone)

where ID is the Oracle sequence ID, and in the hibernate mapping xml file I have <id name="id" column="ID" type="long">
<generator class="sequence">
<param name="sequence">STUDENT_SEQ</param>

And in code I have

Student student = new Student();

... // hibernate session creation
... // session stuff


Now, what does "update" exactly do here ? Since "ID" is the PK and it is generated by oracle sequence, it will never be identical. So how can I actually "update" a row ? for example if there is a row (john, 100 main st, 222-123-1234) before I run the code and I intend to update this row for "john" by changing the address and phone number to (john, 200 main st, 111-222-3333). But since hibernate creates a new ID for it and ID is PK, it is not supposed to "update" the row I think.. It should only "insert" this new row. but that's not what I want. So how can I update that row (what I actually want to do is "updte STUDENT set s.address =:address, := phone where = :name", but that information seems not be incorporated in a simple "session.update(student)"...)
chloe wong

Joined: Aug 02, 2006
Posts: 17
Hi, have you tried using

Raj Ohadi
Ranch Hand

Joined: Jun 30, 2006
Posts: 316
Originally posted by chloe wong:
Hi, have you tried using


No, I haven't. but Since I saw lot of sample codes from books used

"session.update" I think I would like to understand that well first. Could you help me with the questions I asked in the first post ?
I agree. Here's the link:
subject: what does hiobernate Session's update work ?
Similar Threads
save(), update, saveOrUpdate(), merge() ?
help me understand this key mapping in "Hibernate in Action"
why my oracle sequence id increases by 2 when I use hibernate to insert
hibernate primary key mapping - sequence
trigger to check if a row can be inserted or not