-->
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.  [ 7 posts ] 
Author Message
 Post subject: Final considerations on default value on not nullable column
PostPosted: Fri Sep 28, 2007 6:17 am 
Newbie

Joined: Fri Sep 28, 2007 5:51 am
Posts: 8
Hi, I read a lot of topics about setting default values for not nullable columns.
A lot of discussions but not a final "best" solution...

I'm working with Hibernate annotations and I know that "default" option is not supported; somebody says a solution is an interceptor (?), in hibernate sites the proposal is "UserType".

I think this could be a good solution, even if it seems I have to implement a "DefaultIntegerType", another "DefaultDateType", a "DefaultStringType" and so on... I'm right?
Moreover it seems I can't declare my entity with dynamic-insert, because my user type would not be involved.
At last, what is the better solution for fields like "lastUpdateDate" (..not versioning timestamp); I could use another usertype that automatically fill this field with the current date before persist... but, as before, I can't declare my entity with dynamic-update. I'm right?

Please, give me a solution...

Regards,
Fabio


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 7:25 am 
Newbie

Joined: Thu Apr 26, 2007 9:42 am
Posts: 14
What about setting generated="insert" or generated="always"on that attribute mapping, insert="false", update="false" and define at database level for that column default SYSDATE or another db function that generates a timestamp value?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 7:45 am 
Newbie

Joined: Fri Sep 28, 2007 5:51 am
Posts: 8
I know about this solution but:

1- I have to add constraints at database level (...for every default Value!)
(and the use of columnDefinition is not portable)

2- I have to set dynamic update and insert in my Entity, to avoid setting of null values which would cause errors on the not nullable column...

I appreciate your tentative, but it's not the solution I'm looking for.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 7:52 am 
Newbie

Joined: Thu Apr 26, 2007 9:42 am
Posts: 14
See "16.3. Custom SQL for create, update and delete" in Hibernate Reference Documentation, maybe can be a solution.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 8:41 am 
Newbie

Joined: Fri Sep 28, 2007 5:51 am
Posts: 8
No, it's too dispendious.
I would have to rewrite all insert and update statements for entities which contains one "with default" column...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 11:24 am 
Newbie

Joined: Fri Sep 28, 2007 5:51 am
Posts: 8
No other suggestions?

It seems that the problem of setting defaults (...not just a little limitation, I think) is like a taboo in Hibernate community...!


Top
 Profile  
 
 Post subject: Nulls
PostPosted: Mon Oct 15, 2007 3:24 pm 
Newbie

Joined: Mon Oct 15, 2007 3:18 pm
Posts: 15
I have just started with Hibernate and am also wrestling with nulls. I am working from an existing dbase to a rel mapping. Some ints which are actually foreign keys (not explicitly constrained as such) are null. They cause an exception when the table is read ("can't assign null to primitive"). So I used a DefaultValueIntegerType for the column in my hibernate-mapping to default the value to 0. Now the exception is passing a DVIT class to the setter method which expects Integer. Any thoughts? Thanks.

Puzzled in Poughkeepsie


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