-->
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: Using hibernate.hbm2ddl.auto=update with non-null columns...
PostPosted: Tue Apr 04, 2006 9:21 am 
Newbie

Joined: Sun Jul 25, 2004 9:07 am
Posts: 3
Hello all,

I am attempting to use hibernate.hbm2ddl.auto=update to update the schema of the database upon deploy of the application (or more specifically, creation of the session factory).

It seems that when adding a new primitive property to a mapped class, a new column is created in the database but it's values are all null. Hibernate will then complain when trying to load an instance of the class because clearly it cannot set a primitive to null.

What I expected to see was a 'default' value that could be placed in the mapping file so that when the hbm2ddl engine creates the update ddl it will also pre-populate the column to the default value assigned in the mapping document. However, I cannot seem to find any such parameter.

Can anybody offer me any advice?

Thank you for your time.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 10:04 am 
Newbie

Joined: Sun Jul 25, 2004 9:07 am
Posts: 3
Just incase anyone picks this post up on a search, I found the answer.

while <property> doesnt have a 'default' attribute, <column> does. So by specifying in the mapping...

Code:
<property.....>
   <column name="somename" default="10000"/>
</property>


...a default value can be provided.

hbm2ddl does pick up on this value and create the table accordingly.[/code]


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.