The default setting for unsaved-value is null. What is the behavior if you set the value of the id before saving the object? For example:
Session s2 = factory.openSession();
Person p = new Person("test", "me");
p.setId(new Long(8));
s2.save(p);
s2.closet();
Hibernate appears to be ignoring the set id (in this case '8') and putting in its own. Shouldn't I be getting an exception when I do the save?
I took a look through the docs, but couldn't find details.
Thanks,
Mark
Hibernate version: 2.1.6
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.oyl.model.Person" table="Person" discriminator-value="Person" >
<id name="id" column="id" unsaved-value="null"> <generator class="increment" /> </id>
<discriminator column="subclass" type="string"/>
<property name="firstName" column="first_name" not-null="true"/>
<property name="lastName" column="last_name" not-null="true"/>
<subclass name="com.oyl.model.User" discriminator-value="User" >
<set name="todoLists" cascade="all" >
<key column="user_id"/>
<one-to-many class="com.oyl.model.TodoList"/>
</set>
</subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Session s2 = factory.openSession();
Person p = new Person("test", "me");
p.setId(new Long(8));
s2.save(p);
Full stack trace of any exception that occurs: No exception, I just end up getting a row inserted even when my id is not null!
Name and version of the database you are using:HSQLDB 1.7.3
The generated SQL (show_sql=true):
Hibernate: insert into Person (first_name, last_name, subclass, id) values (?, ?, 'Person', ?)
Thanks!
Mark
|