-->
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 values specified in the database
PostPosted: Thu Jun 15, 2006 3:45 pm 
Regular
Regular

Joined: Mon Jun 13, 2005 12:38 pm
Posts: 56
Location: Austin, TX
I have written my pojos to be similar to the pojos in the examples directory of the downloads where the member variables don't have a value. Hence, they are initialized to null. I am running into a situation where the database specifies a column is not null and there is a default value. If I don't set a value for the member using a setter, then the database gives an error. If I set the value to an empty string, then the database will place the default value in the column.

So my work around is to set default values for the strings in the pojo, but I'm not sure if this is the "correct" way of doing things since I don't see it being done in the examples that come with the download.

Do I need to set something in the configuration file or the properties file to use the database default value?


thanks,
Mike


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 16, 2006 12:45 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Either set up the defaults in your pojos, or set the dynamic-insert="true" and dynamic-update="true" attributes on all of your class mappings. These attrbiutes mean that your insert and updates only write columns that have values (and in the case of updates of attached entities, dirty values), so the database defaults will apply to other columns.

The dynamic-X methods do slow your java code down fractionally, as the SQL has to be created on the fly. But if that's not a concern for you, this is the correct solution.

_________________
Code tags are your friend. Know them and use them.


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.