-->
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.  [ 5 posts ] 
Author Message
 Post subject: Mapping null to -1
PostPosted: Tue Jul 19, 2005 2:25 pm 
Newbie

Joined: Mon Apr 11, 2005 2:23 pm
Posts: 2
I created an data object over a legacy database table in which null values represnted as -1.
Is there a way do let hibernate know, in that table only, that when loading an object -1 is null and vice-versa when persist?

Any idea is welcome
Zohar


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 5:12 pm 
Beginner
Beginner

Joined: Tue Apr 05, 2005 4:27 pm
Posts: 40
Location: canada
i would look into a custom usertype to do this.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 3:54 am 
Newbie

Joined: Mon Apr 11, 2005 2:23 pm
Posts: 2
custom usertype is for a specific object, I was aiming for something general.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 5:54 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
well, jaimes tip was perfectly all right ...

With a custom UserTypes you can do this ... i think you won't be able to find a more "general" solution which is as easy as writing some UserTypes, especially because you can find some examples of such UserTypes in the forum.

In Hibernate (as far as i know hibernate) the (User)Types are responsible for reading a value from the resultset (or setting it) and returning the value which will be set into your bean ... so it's the best place to change values, as you need it.

Sure, you have to write a UserType for each type (int, String, long etc.) but that's not really a problem ... they're nearly all the same ...

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 6:00 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
btw ... i've forgot that ...
if you have the possibility to avoid that change, do it! Try to migrate data or something like that, if it's possible! Otherwise you will always have problems with relations, "-1" being a real value and not "null" ... and so on.

I'm having those problems and it has required writing a lot of UserTypes and own persisters to fix some errors ...

Therefor, the best hint i can give you is to try to migrate the data if it's possible ... (in my case it's not possible :( )


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