-->
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.  [ 11 posts ] 
Author Message
 Post subject: null database fields and primitive types
PostPosted: Sat Apr 17, 2004 5:10 pm 
Newbie

Joined: Sat Apr 17, 2004 5:05 pm
Posts: 5
Location: Toronto, Canada
Simple question:

How does hibernate handle a field that maps to a primitive type when it is null?

Feature questions/request:

Does the ability to specify on the hibernate descriptor a value to use if the field return was null sould useful? (i.e. null-value="-1")


Martin


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 17, 2004 7:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You get an exception when trying to load a null value into a primitive type. You can however use a custom UserType very easily to handle such value conversions.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 9:47 am 
Newbie

Joined: Sat Apr 17, 2004 5:05 pm
Posts: 5
Location: Toronto, Canada
Does the potential feature sound useful? Making a custom UserType to handle all the primitives and mapping them into all my value objects seems cumbersome. I would be willing to develope this, but would need a bit of guidence as to the best place to put this.

I personally hate nulls in the database, but there are situations where they are unavoidable....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 10:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
IMHO the existing solution is sufficient, you can however enter a feature request in JIRA if you want.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 10:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Don't create a feature request, since I will just reject it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 10:48 am 
Newbie

Joined: Sat Apr 17, 2004 5:05 pm
Posts: 5
Location: Toronto, Canada
Just out of curiousity, Gavin, why would you reject it outright? In your opinion is the better design to always use the Object wrapper for primitives on a value object?

Martin


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 9:27 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Because it's only here to solve a specific case and UserType is way more powerful.
Such specific features are quite common and would pollute the mapping file quickly

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 2:46 pm 
Newbie

Joined: Tue Apr 20, 2004 11:12 am
Posts: 5
Location: Sao Paulo / Brazil
But supose you have lots of tables with numeric columns mapped to primitive types and these columns have different default values.

This is a common scenario.

Shoul I create a custom type for every diferent default value?

I agree with martin. I think that there should by a parameter like (null-value="0")

Fabio


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 7:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You have to create a custom UserType for every case. How many default values do you have, there are not many sensible cases besides -1 and 0. This might probably become easier in future versions with parametrizable UserTypes.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 7:15 am 
Newbie

Joined: Sat Apr 17, 2004 5:05 pm
Posts: 5
Location: Toronto, Canada
I have scenarios where it's not defaulting to 0 or -1, but also Integer.MAX_VALUE and Integer.MIN_VALUE.

Can you do primitive types using UserTypes? What is the intended functionality of a parametrizable UserTypes? I have a need for this, so I would be willing again to help develop this? Is there a JIRA for this feature?

Martin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 8:42 am 
Newbie

Joined: Tue Apr 20, 2004 11:12 am
Posts: 5
Location: Sao Paulo / Brazil
I work on a big Human Resource system. There are more than 900 tables.

I have the data dictionary stored in tables. I've searched for columns whose default values are different than 0, -1 and the amount is 40 different default values.

I think this new "null-value" parameter would help a lot and it's an additional resource for hibernate

Fabio


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