No sure why I'm NOT getting an error in this case, I obviously don't get something about the meaning of unsaved-value="null". I figured that if an object's id was already set, then Hibernate would see it as non-null and throw some kind of exception when trying to save. Why not?
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
|