• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

saveOrUpdate always updates

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

I need to save or update an object to the database.
I use the seeion.saveOrUpdate(myobj) method but it always updates the object even the 1st time when the object is created. And hence the object is never stored to the db.


The hbm file is as follows :

<class name="MyClass" table="Mytable" lazy="true" dynamic-update="true" dynamic-insert="true">
<meta attribute="extends">MySuperClass</meta>
<cache usage=nonstrict-read-write"/>
<composite-id class="MyPK" name=Id">
<key-many-to-one column="mycolumn1" name="myColumn1" class="MyColumn1"/>
<key-many-to-one column="mycolumn2" name="myColumn2" class="MyColumn2"/>
</composite-id>
....

can anyone please tell me what is wrong ?

thanks
Gayatri
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from hibernate docs:


You may instead implement Interceptor.isUnsaved() if you wish to use saveOrUpdate() or cascading save / update. As an alternative, you may also set the unsaved-value attribute on a <version> (or <timestamp> element to specify a value that indicates a new transient instance. In this case, the version of the entity is used instead of the (assigned) identifier and you don't have to implement Interceptor.isUnsaved() yourself.


http://www.hibernate.org/hib_docs/reference/en/html/components.html


pascal
 
Gayatri Ganesh
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Pascal
 
reply
    Bookmark Topic Watch Topic
  • New Topic