openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john <j...@zode64.com>
Subject Re: CheckDatabaseForCascadePersistToDetachedEntity=true in OSGi
Date Thu, 01 May 2014 17:57:28 GMT
Hi Rick

Thanks for the response.

There are too many classes with different characteristics for me to enjoy
pulling it into 1 persistence unit.

I can't make the catalog transient as I need to save a reference of it to
the model. However I only need to save the foreign key to the model and
don't want to be able to modify it. Is there as simple way of doing this?

Cheers
John
On 1 May 2014 12:07, "Rick Curtis [via OpenJPA]" <
ml-node+s208410n7586327h11@n2.nabble.com> wrote:

> > 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)
>
> The problem is that you're trying persist an Entity(model) that has a
> relationship to another Entity(catalog) that is from a different
> persistence unit. From the model-persistence persistence unit's point of
> view, the catalog that is referenced by your model is a non-persistent
> field.
>
> I'm reaching a bit here, but I think you have two options. Either compress
> down to one persistence unit, or mark model->catalog as @Transient so that
> relationship will be ignored by OpenJPA.
>
> Thanks,
> Rick
>
>
> On Wed, Apr 30, 2014 at 1:26 PM, John Bower <[hidden email]<http://user/SendEmail.jtp?type=node&node=7586327&i=0>>
> wrote:
>
> > 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
> >
>
>
>
> --
> *Rick Curtis*
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://openjpa.208410.n2.nabble.com/CheckDatabaseForCascadePersistToDetachedEntity-true-in-OSGi-tp7586298p7586327.html
>  To unsubscribe from CheckDatabaseForCascadePersistToDetachedEntity=true
> in OSGi, click here<http://openjpa.208410.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=7586298&code=am9obkB6b2RlNjQuY29tfDc1ODYyOTh8MjA5NDAyMjk0NA==>
> .
> NAML<http://openjpa.208410.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://openjpa.208410.n2.nabble.com/CheckDatabaseForCascadePersistToDetachedEntity-true-in-OSGi-tp7586298p7586329.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message