-->
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: How to handle DB null value mapping to Java primitive?
PostPosted: Thu Feb 01, 2007 5:10 pm 
Beginner
Beginner

Joined: Fri Jan 26, 2007 3:16 pm
Posts: 24
Hi, I map most values to hibernate types that end up being java primitives (int, long). However, in the event that the value is null in the DB, this throws an exception.

Is there a recommended way to deal with this that doesn't involve mapping to autoboxed java objects?

Thx in advance,
davis


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 8:24 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Not if you want the value to be read-write. If it's read-only, you could map it with a formula: formula="isnull(col, 0)" or similar.

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 9:41 pm 
Beginner
Beginner

Joined: Fri Jan 26, 2007 3:16 pm
Posts: 24
Hi, thx for the response. A quick follow-up...

I'm dealing with a Table that has three columns that map to String, int, long. The value is mutually exclusive meaning only one is populated per row.

We deal with huge amounts of data, and I'd like to avoid the overhead of objects where primitives will do. But I'll take the overhead of an object if I can only grab the non-null value...for example:

If I define an interface like this:

Code:
public interface SimpleAttribute<T> {
  T getValue( );

  void setValue(T value);
}


...and during the fetch, only get the value that is non-null (one of Integer, Long, String) and store it as parameter T?

I'm not sure how to configure Hibernate (admitted newbie) to deal with an interface like that, and also how to have it only fetch the non-null value from the columns. Any pointers on how to do this?

Thank you,
davis


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 11:01 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
No, that's not the sort of thing that a generic framework like hibernate does. You'll have to do that in java code.

By and large, if you want a column to be a true primitive, it should be NOT NULL in the DB. You will have to map strange arrangements like yours as wrappers and use autoboxing.

_________________
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.  [ 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.