-->
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: Behavior of Session.save() and duplicate data
PostPosted: Fri Apr 09, 2004 3:44 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
Is the intended behavior of session.save() to always insert a new row into the database, regardless of whether an instance has already been persisted (i.e. the instance already has a generated PK id)?

If I attempt to pass an already persisted instance to session.save() it inserts a new row with identical data, but with a new generated PK id.

I am using Hibernate 2.1.2 with DB2 8.1.

Here's the XDoclet markup on the id column of my class I am persisting:
@hibernate.id column="id" type="integer" generator-class="identity" unsaved-value="null"

And the DDL for my test table is like this:
Code:
create table test.something
(
  id integer not null primary key GENERATED BY DEFAULT AS IDENTITY,
  version integer,
  description varchar(60),
  date_opened timestamp,
  date_last_updated timestamp
);


If this is the intended behavior then it sounds like in this case I should be using saveOrUpdate() instead?

Thanks,
Kevin


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 09, 2004 3:46 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Use saveOrUpdate(), of course.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.