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