-->
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: why no exception using unsaved-value="null"
PostPosted: Sun Mar 06, 2005 8:28 pm 
Newbie

Joined: Wed Jan 21, 2004 10:09 am
Posts: 13
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 10, 2005 10:34 am 
Newbie

Joined: Thu Mar 03, 2005 1:52 pm
Posts: 5
any feedback on this?


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.