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