all that jazz

james' blog about scala and all that jazz

JPA 2.0 - Early Review

A few days ago, JSR-317, the specification request for JPA 2.0, released an early draft review of the specification. Today I had the chance to skim through it to see what new things it had to offer.

Something I commented on in an earlier blog post was how they might implement deleting orphan members of an association. Would they follow TopLink's private collection mapping, or use Hibernate's additional delete orphan cascade type? It turns out, they chose neither... or rather, they met half way. The EDR specifies the addition of a boolean orphanRemoval attribute on the @OneToMany and @OneToOne annotations. So the terminology follows the Hibernate orphan terminology, however hibernate uses a DELETE_ORPHAN cascade type. The method though is more similar to TopLink, which has private ownership as a property of a collection mapping.

I don't think that I like this way of doing it. I don't think it's consistent, if I want a new entity to be persisted just by adding it to a collection, then I specify cascade=PERSIST. But if I want an existing entity to be deleted just by removing it from a collection, then I specify orphanRemoval=true. Cascading persistence to members added to collections and removing orphaned elements are both similar operations, in that they indirectly change the life cycle state of an entity, that occur at flush time, in a cascade like manner. I think it would be more consistent to say cascade=ORPHAN_REMOVE. The expert group has made a note in the EDR asking for input on which strategy they should use.

comments powered by Disqus

About

Hi! My name is James Roper, and I am a software developer with a particular interest in open source development and trying new things. I program in Scala, Java, PHP, Python and Javascript, and I work for Lightbend as a developer on Lagom. I also have a full life outside the world of IT, am a passionate Christian, enjoy playing a variety of musical instruments and sports, and currently I live in Canberra.

I also have a another blog called Roped In about when my wife and I lived in Berlin for a year to help a church reconnect with its city.