Hey,
I'm using the ' unsaved-value="0" ' setting within my mapping file. In the code I'm getting a user object that exists from database. When I change a property (for example online=1) and then use ' getHibernateTemplate().save(user); ', the user is not updated but inserted with a new ID as a new entry in the database.
I debugged the code and everything seems to be okay. The user I get from the database has its ID other than 0. So why does Hibernate create a new entry?
Hibernate version: 3
Mapping documents: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="de.tfhberlin.eclipsophone.server.beans" auto-import="true"> <class name="User" table="User" lazy="false"> <id name="id" column="id" type="long" unsaved-value="0"> <generator class="native"/> </id> <version name="version" column="version" unsaved-value="negative"/> <property name="name" column="name" type="string"/> <property name="password" column="password" type="string"/> <property name="ipaddress" column="ipaddress" type="string"/> <property name="enabled" column="enabled" type="int"/> <property name="online" column="online" type="int"/> <set name="subscribed_groups" table="UserGroup" inverse="true" lazy="false"> <key column="user_id"/> <many-to-many class="Group" column="group_id"/> </set> <set name="offlinemessages" table="OfflineMessage" lazy="false"> <key column="receiver_userid"/> <one-to-many class="OfflineMessage"/> </set> </class> </hibernate-mapping>
|