-->
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: NULL is NULL or 0
PostPosted: Thu Aug 12, 2004 10:22 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
I'm busy adapting Hibernate to an old DB Schema. The DB is and will be used by a number of legacy applications which I cannot change.

The Problem I'm facing is, that sometimes 0 is used to express NULL semantics and sometimes a real NULL is used for the same column. I'd like to make this transparent to my new java business logic.

Is it a good idea to create a user type with a nullSafeGet which returns a java null in case it reads 0 or NULL from the DB?

I think this works fine, if the user type is used for an ordinary property.
What happens if the column is part of a foreign key? My guess is that it's still using the nullSafeGet of the user type, which means it's ok.
Does is also work wiht HQL? I don't think so, how can Hibernate now that an
Code:
id=NULL
should be expressed as an
Code:
id=NULL or id=0


Are my thoughts correct? Is there a (better?) way to do that and maybe have the HQL case working as well?

Best Regards
Ernst



Hibernate version:
2.1.4


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 11:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You have to do things like that in HQL yourself - you should know your DB schema. Besides, id=null won't work anyway, you have to use "id is null"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 11:49 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
What about the ordinary property and the foreign key case? Do they work as expected?

Best Regards
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 11:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You mean thinks like having a "not-set" foreign key represented as 0 and not as null? That will not work. Hibernate requires a minimally intact relational schema.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 1:48 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Does this mean the only way to get this relations working with Hibernate is to convince the dba and the other application owners to cleanup their code/databases?

Mmm ... that's bad news.

Thanks for you help anyway.
Ernst


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.