| A simple chain of 3 Entities with unidirectional ManyToOne associations and cascade = CascadeType.PERSIST to their parent entity works if every Entity has a simple id (also if they all have a sequence generator for that id). Chain: Company ---o Department ---o Employee If the last Entity (most dependent) in the chain (here Employee) uses an IdClass annotation in order to reuse the id of its parent entity then:
- a) The column for that parent id can not be updatable = false or nullable = false
- b) If all a newly created and only Employee persisted, then the Order of statements is:
- INSERT Department
- INSERT Employee
- INSERT Company
- Update for Department
Effects:
- The foreign key column for the Department Id inside the Employee table must be nullable.
- Unnecessary roundtrip to the database for the UPDATE statement.
Observed Behavior: org.hibernate.action.internal.UnresolvedEntityInsertActions logCannotResolveNonNullableTransientDependencies Department.java Employee.java Company.java EmployeeId.java JPAUnitTestCase.java WARN: HHH000437: Attempting to save one or more entities that have a non-nullable association with an unsaved transient entity. Expected Behavior: Foreign key column in Department can be annotated with nullable = false. No additional UPDATE will take place. |