Hibernate has always had the ability to automatically apply the persist operation to a new entity referenced by an association at flush-time. Historically, this feature, along with orphan deletion, was mixed into our native CascadeTypes, and was never an explicit option.
JPA 2.0 added separated orphan deletion into a dedicated orphanRemoval setting, which is fine and at least arguably better, but it seems like the "auto persist" side of this escaped everyone's attention (including mine).
I happen to think this is pretty useful, and so I would propose adding a new setting to association mapping annotations, so that you could write, for example:
Then you could make a Child persistent simply by calling parent.children.add(child) with no explicit call to em.persist(). Of course the Child only becomes persistent after a flush.
Hibernate has always had the ability to automatically apply the
persist
operation to a new entity referenced by an association at flush-time. Historically, this feature, along with orphan deletion, was mixed into our nativeCascadeType
s, and was never an explicit option.JPA 2.0 added separated orphan deletion into a dedicated
orphanRemoval
setting, which is fine and at least arguably better, but it seems like the "auto persist" side of this escaped everyone's attention (including mine).I happen to think this is pretty useful, and so I would propose adding a new setting to association mapping annotations, so that you could write, for example:
Then you could make a
Child
persistent simply by callingparent.children.add(child)
with no explicit call toem.persist()
. Of course theChild
only becomes persistent after a flush.