-->
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.  [ 4 posts ] 
Author Message
 Post subject: Safe Nulls
PostPosted: Wed Aug 27, 2003 9:32 am 
Newbie

Joined: Wed Aug 27, 2003 9:25 am
Posts: 4
Is it possible to setup default values for not-null columns, which can be used if the value of the corresponding class property is null? Or is there some feature of Hibernate I'm missing that will take care of this for you? TIA.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 10:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
You pretty much have two options:
1) use an Interceptor to inspect for null attributes and set a default value; or
2) use write a UserType.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 27, 2003 10:03 am 
Beginner
Beginner

Joined: Tue Aug 26, 2003 9:50 am
Posts: 34
Location: Weiden Opf. / Germany
Hi there!

I have another question to the same topic.

Is there a way to tell hibernate to just ignore null attributes of a Java Object to be persisted?

We set up our database to have many colums as not null, but specified a default value.

When i now instatiate a new object, set some of it's attributes and try to persist it, Hibernate throws an exception like: "cannot insert null in column blah, this column doesn't allow null values".

I'd like hibernate to just not include these null attributes in the insert statement and let the db fill it with default values.

Actually while i think about it, maybe the easiest thing is just to initialize the Java Objects with the same default values as specified in the db.

what do you think?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 27, 2003 10:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
(1) don't map the properties with not-null="true"
(2) set dynamic-insert="true"


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.