-->
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.  [ 1 post ] 
Author Message
 Post subject: No exception, don't understand!
PostPosted: Fri Mar 11, 2005 12:14 pm 
Newbie

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.