0 Replies Latest reply on Jul 10, 2006 11:20 AM by Sean Dawson

    Data Transfer Objects / Optimistic Locking / Merging Entitie

    Sean Dawson Newbie


      We are using the Data Transfer Object (DTO) pattern to pass data to our clients, rather than passing up the entity beans. Unfortunately, due to time constraints, we may not be able to switch to passing the Entity Beans directly.

      We are having a problem dealing with optimistic locking. We've placed @Version fields in the entity beans, and version properties in the DTO objects. We construct the DTO on the server, set its version to equal the entity, and then send the DTO to the client. When the client wishes to save the entity, we find the old entity, set the version on the entity to match the DTO, and then flush the changes to the database.

      After testing, the entity manager is not throwing an optimistic lock exception. The EJB specification states that the optimistic lock exception is only done when merging detatched entities. We then tried to create a new Entity in the server, populate the data to match the DTO, and then merge. This does work fine, but if the DTO only contains a subset of the information found in the entity, the remaining fields will be nulled. Is there an easy way to only update the fields contained in the DTO, while ignoring the others?

      If you use the DTO pattern with JBoss, I'd like to learn how you deal with this issue. Thank you,