-->
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: Default property values (still) don't work in Hibernate 3.1
PostPosted: Thu Feb 02, 2006 5:00 pm 
Newbie

Joined: Tue Dec 27, 2005 3:30 am
Posts: 11
Default property values do not work in Hibernate 3.1. I asked earlier about this and the answer was turn on "dynamic-isert" for the class. I did that and it still does not work. The objective is to have an initial optional default value on an not-null field. This is the usual purpose of the SQL column default clause. I know I can put the default in the class constructor, but that defeats the purpose of the dynamic-component used here:

Quote:
<class entity-name="TestPerson" table="TEST_PERSON"
name="com.test.TestPerson"
dynamic-insert="true">
<id name="Id" column="testPersonId">
<generator class="native"/>
</id>
<dynamic-component name="Members">
<property name="testBoolean" type="boolean">
<column name="testBoolean" default="false" not-null="true"/>
</property>
</dynamic-component>
</class>


Insert generates this SQL:
Quote:
insert into TEST_PERSON (testBoolean, testPersonId) values (?, null)


Which gives this error:

org.hibernate.PropertyValueException: not-null property references a null or transient value: TestPerson.Members.testBoolean


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 12, 2006 9:44 pm 
Newbie

Joined: Tue Dec 27, 2005 3:30 am
Posts: 11
It does generate the correct DDL, but Hibernate insists on inserting a null instead of using the default, even if dynamic-insert="true"

This in the xml document:
Code:
            <property name="testProperty" type="string">
                <column name="testProperty" default="'default string'"/>
            </property>


produces this schema:
Code:
testProperty varchar(255) default 'default string'


Which is right, but Hibernate insists on inserting a null value.

This is very disappointing as it means we have to put the defaults into the code and not into the xml, as we hoped.

Has anyone solved the puzzle, or does it really not work?

TIA


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.