Hi My setup is - servicemix 5.0.0, openjpa 2.2.2, Mysql 5.5 database.
I have 4 bundles, model-persistence, catalogs-persistence, models and catalogs. The 2 persistence bundles each have a persistence unit. The model-persistence bundle provides an OSGi service to save a model which is defined in in the models bundle. The catalogs-persistence provide a readonly get services which gets catalogs which are referenced by the model. When I try save a model which has a reference to one of the readonly catalogs (which I don't want to update) and which I get through the catalogs-persistence service (so the model-persistence is handling an object from another persistence unit) 15:09:53,324 | DEBUG | ectronica/create | ServiceRecipe | 7 - org.apache.aries.blueprint.core - 1.4.0 | Method entry: getService, args org.apache.karaf.jndi.KarafInitialContextFactory@2cf5e0f0 15:09:53,339 | DEBUG | ectronica/create | context | 199 - org.apache.aries.jpa.container.context - 1.0.1 | Created a new persistence context org.apache.aries.jpa.container.impl.EntityManagerWrapper@7933da2e for transaction [Xid:globalId=10ffffffe51effffffb4451006f72672e6170616368652e61726965732e7472616e73616374696f6e0000000000000000000000000000,length=64,branchId=0000000000000000000000000000000000000000000000000000000000000000,length=64]. 15:09:53,512 | WARN | ectronica/create | Transaction | 230 - org.apache.aries.transaction.manager - 1.1.0 | Unexpected exception from beforeCompletion; transaction will roll back <openjpa-2.2.2-r422266:1468616 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException: Encountered unmanaged object "catalog.Catalog-673" in life cycle state unmanaged while cascading persistence via field "model.Model.catalog" during flush. However, this field does not allow cascade persist. You cannot flush unmanaged objects or graphs that have persistent associations to unmanaged objects. Suggested actions: a) Set the cascade attribute for this field to CascadeType.PERSIST or CascadeType.ALL (JPA annotations) or "persist" or "all" (JPA orm.xml), b) enable cascade-persist globally, c) manually persist the related field value prior to flushing. d) if the reference belongs to another context, allow reference to it by setting StoreContext.setAllowReferenceToSiblingContext(). FailedObject: catalog.Catalog-673 at org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(SingleFieldManager.java:786) at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:621) at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:589) at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:505) at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:3018) at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:44) at org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:1034) at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2122) at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2082) at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:2000) at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:527) at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:511) at org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:413) I was thinking that this is what the CheckDatabaseForCascadePersistToDetachedEntity=true property is so I added it to the persistence unit. <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"> <persistence-unit name="model" transaction-type="JTA"> <class>model.Model</class> <exclude-unlisted-classes /> <properties> <property name="openjpa.Compatibility" value= "CheckDatabaseForCascadePersistToDetachedEntity=true" /> </properties> </persistence-unit> </persistence> But it doesn't change anything. Should this option remove the problem I am having? Should it work in OSGi? Are there any suggestions as to what I am doing wrong and if it is possible at all? Cheers John