• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

what does hiobernate Session's update work ?

 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
</generator>
</id>

And in code I have

******
Student student = new Student();
student.setName();
student.setAddress();
student.setPhone();

... // hibernate session creation
... // session stuff
session.update(student);

*********

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, s.phone := phone where s.name = :name", but that information seems not be incorporated in a simple "session.update(student)"...)
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, have you tried using



instead
 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by chloe wong:
Hi, have you tried using



instead



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 ?
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic