I have an Order
entity and table and inside the entity Order
class, I have this:
@ManyToOne
@JoinColumn(name = "CUST_COMP_ID")
private CustomerCompany custCompany;
public CustomerCompany getCustCompany() {
return custCompany;
}
public void setCustCompany(CustomerCompany _custCompany) {
this.custCompany = _custCompany;
}
In the DB, the column CUST_COMP_ID
is a FK from Order
to another table.
The problem is that the DB table Order
contains zeroes (in that FK column) when it means NULLs which is a pretty non-standard way to store NULLs (i.e. empty FK values).
Can I somehow tell Hibernate to map those zero values so that when the FK value in the DB is zero, the customerCompany
field/property is loaded/populated as null
by hibernate in the Order
entity?
While researching, I found this old Hibernate forums topic:
https://forum.hibernate.org/viewtopic.php?f=1&t=933785
but I have 2 problems with it: 1) I don't know how exactly to extend ManyToOneType to achieve this; 2) I don't know if this information is valid and up-to-date at all (the topic is very old).
I guess there should be some simpler, more elegant way to achieve my goal.