Issue
I use Hibernate to access to a legacy DB. For some tables the parent-child reference integrity is not enforced, and the long
0 value is used instead of NULL for some "parent" columns in child tables to denote "no parent".
I still want to use these relations in @ManyToOne
and @OneToMany
fields, but get EntityNotFound
error since the 0 value does not correspond to any record in master table.
What are my options?
Solution
Use the NotFound
annotation:
@NotFound(action = NotFoundAction.IGNORE)
See http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#mapping-declaration-manytoone
Answered By - JB Nizet
Answer Checked By - David Goodson (JavaFixing Volunteer)