Hibernate handle long 0 value instead of NULL in ManyToOne relations
问题 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? 回答1: Use the NotFound annotation: @NotFound(action = NotFoundAction.IGNORE) See