'Cascade parent-child relation with Hibernate

I have a real-life situation, where objects are organized as this: one tree has more branches, one branch has more leaves, one leave has many colors, and so on. From my experience, this seems to be a common pattern when dealing with a non-trivial model.

In Hibernate it is not possible to nest ElementCollections. Therefore developers have to fake this functionality with multiple OneToMany associations.

Assuming the (not-recommended) situation when I'm receiving an entity as a @ResponseBody parameter,

Is there a technique to use cascade to deal with this for both insert and update? How to deal with child entities that already exist?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source