Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1.1
Hibernate Annotations: 3.1beta8
I'm working with a legacy database that for some stupid reason sometimes uses zeroes in fields that link records to parents in the same table, where 0 actually means null (i.e. the record has no parent - there is no record with an id of 0).
Obviously, there is no foreign-key defined on the database for this particular relationship (since it would fail), however I want to map this relationship as a many-to-one with a fetch type of EAGER. Unsurprisingly, at present this generates an UnresolvableObjectException, since there is no parent row with an id of 0.
What is the best way to tell Hibernate that zeroes should actually be treated as nulls (and nulls should be persisted as zero)? Note that I am using Hibernate Annotations rather than a mapping file, so I'm not sure how or if I can use the custom SQL for loading option, assuming that this is the preferred approach.
I'd like to avoid mapping files, for the simple reason that the legacy database has approximately 180 tables, which is a lot of XML...
Many Thanks!