« What Is Blogging?... | Main | JUG HH Rocks, Java... »
 20080518 Sunday May 18, 2008

Generic EJB 3 CRUD, DTOs and Lost Updates with Optimistic Locks and JPA

I got some feedback with concerns about a generic CRUD interface which I described in this post, as well as checked in into p4j5. The basic idea was the direct exposure of persistent JPA-entities to a remote client - without the use of DTOs. This approach works really well for simple use cases like e.g. master data management. However it isn't a silver bullet for more complex use cases. In general, the @Version in an JPA-entity is going to change in case the persistent state (the attributes) is changed. However the relations do not belong to this set. So, even in case you are using JPA with optimistic concurrency, changes to relations do not cause the @Version attribute to be increased / changed. In case the client changes a relation (e.g. deletes a link between the master 1----n> client), the @Version of the master entity will not be increased - concurrent access could cause lost updates in this case.

Beyond this "logical" problem - before you would like to start using detached entities over network boundaries, you should think about the following challenges:

However - you can get rid off the most problems (except the "relations-versioning") running the persistence (business) layer in the same JVM as the presentation e.g. in a JSF enviroment it is perfectly possible.
I will discuss this issue in more detail during the upcoming talk at JUG HH (19.05.2008) as well.
Gesendet von admin [Java / JEE / Architecture] ( May 18, 2008 11:54 AM ) Permalink | Kommentare [1]
[my website] [This entry is based on / extends my books: Enterprise Architekturen, Leitfaden fuer effiziente Software-Entwicklung and: Java EE 5 Architekturen, Patterns und Idiome]

Kommentare:

If using Hibernate as the JPA provider, the BeanLib project can un-weave the entities to solve points 2 and 3.

http://beanlib.sourceforge.net/

Greg

Gesendet von Greg Burrow am May 19, 2008 at 10:11 PM CEST #

Senden Sie einen Kommentar:

Name:
E-Mail:
URL:

Ihr Kommentar:

HTML Syntax: Ausgeschaltet



License
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 2.0 License.