-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: save() and unsaved-value
PostPosted: Tue Feb 15, 2005 9:40 am 
Newbie

Joined: Fri Oct 01, 2004 3:37 am
Posts: 2
Location: France
Hi,

I'm not sure about this behavior, so i'd like someone to confirm (or not).

This is a simple sample code to illustrate the problem. I have a class, Compte, with id of type long and with unsaved-value = "-1". (I use DAO generated by hibernateSynchronizer...)

If i get an existing object c1 from DB and then call DAO.save(c1) on it, a new object with same properties value as c1 will be created with a new id value !!!
There is no care taken on the id value which is NOT unsaved-value.

The code is only
Compte c = compteDAO.load(id); => session.load(class, id);
// modify c...
compteDAO.save(c); => session.save(c);


My feeling is that session.save() suppose the Object is a new one and generate a new id for it (in my case) without regarding if its effectively a new object or not ....
What makes me hesitate is that when I started to use hibernate, I think I have tested that and I think (I'm not really sure) it was not the case : save() generated an exception if trying to save a existing object ...
I know there is saveOrUpdate() method but it's to understand save() behavior...

Thanks for your help
Regards
Veronique


Hibernate version: 2.1.8
+ PostGreSql 7.3

Mapping documents:
<hibernate-mapping package="test.sh">
<class name="Compte" table="compte">
<id column="id" name="id" type="long" unsaved-value="-1">
<generator class="vm" />
</id>
<property column="credit" name="credit" not-null="false" type="double" />
</class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.