javaspring-boothibernate

Is it possible to merge multiple non persisted child entities at once?


I am trying to save multiple new entities to the database via a parent entity cascadeType. The structure is as follows:

In the end I call MachineRepository.save on the machine object. The Machine and ProductLinkBox object is successfully persisted, but nothing else. Do I need to manually persist all of the other types as well? Is hibernate not able to automatically persist all of the other parent - child relations?

EDIT: Solved by following Vlad Mihalceas OneToOne mapping instructions in combination with the code from his github link.


Solution

  • Solved by following Vlad Mihalceas OneToOne mapping instructions in combination with the code from his github link. Removing the unnecessary ID mappings from the entities and using a shared PK did the trick.