• 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
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Hibernate - saveOrUpdate = insert or update?

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

is the hibernate saveOrUpdate method supposed to insert/update a hibernate object?

I have a new object that I am passing to saveOrUpdate, and I am not finding it in the DB.

Thanks,

Joshua
 
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should save if I recall correctly, any errors?
enable logging, sql queries as well, and post the output if it doesn't tell you enough.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will INSERT or UPDATE depending on the value of the objects identifier (PK if you will). If your transient object has an identifier value, then update() is called, if it doesn't save() is called (which generates an identifier). So your new object should be inserted, unless you have already assigned an identifier which isn't in the DB, in which case an update statement will be called on a record that doesn't yet exist - which won't work of course. Show us your code if you are still confused.
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
this must be create/update a new record ,
There is two cases
1. if user is trying to create a new record then primary key will be automatically created for the table

then hibernate will create a new record

while creating the record it will check the primary key inside the table and then create a new value for the key

2. if user will try to update the record then hibernate will get the primary key and it will update hte record insted of creating a new one
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

did you close the session and commit your transaction ? If not the new record will not make it to the DB.



cheers

pascal
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic