I work with Hibernate and JPA. I have an object called Customer
that references ParentCustomer
:
public class Customer { @Id @GeneratedValue @Column(name = "CustomerID") private int id; @ManyToOne @JoinColumn(name = "ParentCustomerID") private Customer parent;
But there are some clients in my db that don't have a parent, so the ParentCustomerID
parameter ParentCustomerID
set to 0
. The exception that I get when testing my class is:
javax.persistence.EntityNotFoundException: Unable to find it.keyforup.pat.data.entities.Customer with id 0
Is there a way to set ParentCustomer
to null
when id is 0
?
source share