javax.persistence.EntityNotFoundException: Unable to find <entity_type> with id <id_value> in Hibernate
Issue
-
An
ManyToOneassociation is defined@Entity public class Employee { @Id private String name; ... @OneToMany(mappedBy = "employee" ...) private List<Task> tasks; } @Entity public class Task { @Id private long id; private String name; @ManyToOne private Employee employee; } - Referential integrity constraints were not created in the underlying database for the
Task.employee_namecolumn. - A
Taskrow references a non-existent row (with the name 'John Smith') in theEmployeetable. -
When loading the
Taskinstance with the unresolvableEmployeereference, an exception is raised:javax.persistence.EntityNotFoundException: Unable to find support.hibernate.entity.Employee with id John Smith
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 7
- Hibernate 5
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.