• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

saveOrUpdate always updates

 
Gayatri Ganesh
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • 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
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Pascal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic