-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate always INSERTs instead of UPDATE
PostPosted: Wed Dec 27, 2006 1:01 pm 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
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>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 27, 2006 1:24 pm 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
Ok, the problem was save(). I have to use saveOrUpdate() -.-


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

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.