Java Mailing List Archive

http://www.gg3721.com/

Home » users.openjpa »

How to prevent OpenJPA from updating immutable entities?

Enrico Goosen

2008-08-13

Replies: Find Java Web Hosting

Author LoginPost Reply

I'm using OpenJPA with GWT, and therefore I'm copying my model object to a
GWT friendly DTO, before passing it to the frontend (and visa versa when
returning from the frontend).

When I check my debug output, I notice that there are update statements for
entities that are supposed to be immutable (the database values don't
change).
So I tried removing cascade = { CascadeType.PERSIST,CascadeType.MERGE }, to
prevent the immutable entity from getting updated, but then I get this
error:

org.apache.openjpa.persistence.InvalidStateException: Encountered unmanaged
object in persistent field

Then I added this method to my DAO:
public TblScmpdt attachImmutableRelationships(TblScmpdt tblScmpdt){
   EntityManager em = getEntityManager();
   TblPdtcde tblPdtcde = em.find(TblPdtcde.class,tblScmpdt.getPdtcdeId());
   tblScmpdt.setTblPdtcde(tblPdtcde);
   return tblScmpdt;
 }

but I still get the InvalidStateException.

How do I stop OpenJPA from trying to merge/persist my immutable entities?

--
Sent from the OpenJPA Users mailing list archive at Nabble.com.

©2008 gg3721.com - Jax Systems, LLC, U.S.A.