vendredi 2 septembre 2016

JPA design for serialized entities

I'm looking for input into a design approach. I have a requirement to serialize an entity, send it to a remote client that does not have a JPA client, get it back and then update the database.

I have the first three portions working fine. My questions is the approach for saving the entity after it is returned from the client.

My current approach is:

  1. Retreive it again from the database so it is managed
  2. Check the version to prevent concurrent modifications
  3. Copy the fields from the serialized entity to the managed one
  4. Save the managed entity using merge()

I would appreciate your input on several aspects

  1. Is there a better overall approach to saving the modified entity?
  2. When copying the fields a simple field assignment is not recognized as a modification but a setter is a change

    2a. this.name = modified.getName() results in no update statement sent to the database

    2b. this.setName(modified.getName()) results in an update

  3. Collections of children are throwing ClassCastException. How can I successfully update (add/remove/change) a collection?

This is with openjpa 2.4.1 if it is relevant to the discussion.

Thanks for your input!

Tim

Aucun commentaire:

Enregistrer un commentaire