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).
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 the company_id in department can not be updatable = false or nullable = false
b) If all Entity instances are new created and only Employee is persisted, then the Order of statements is:
Update for Department
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 if company_id is not nullable:
WARN: HHH000437: Attempting to save one or more entities that have a non-nullable association with an unsaved transient entity.
Foreign key column in Department can be annotated with nullable = false.
No additional UPDATE will take place.
MacOS 10.14.5, openjdk version 11.0.2, hibernate-core-5.3.9, hibernate-java8-5.3.9, hibernate-validator-6.0.15, hibernate-commons-annotations-5.0.4, javax-persistence-api-2.2, Apache Derby 10.14.2.0