> I cached some objects which were fetched in a separate persistence
context, I just wonder if I can keep the objects active cross the different
persistence contexts.
That is a fair(ish) answer... but I'll note that you'll want to be very
careful. Your mileage may vary when setting this property and you might
encounter some unexpected behavior. Let us know how it works out for you.

((EntityManagerImpl)
em).getBroker().setAllowReferenceToSiblingContext(true);

Thanks,
Rick


On Tue, Feb 12, 2013 at 9:38 AM, Alex <[email protected]> wrote:

> Rick,
>
> I cached some objects which were fetched in a separate persistence
> context, I just wonder if I can keep the objects active cross the different
> persistence contexts.
>
>
>
>
> Alex
>
> From: Rick Curtis
> Date: 2013-02-12 23:07
> To:
> CC: users
> Subject: Re: Re: How to get the reference of StoreContext
> > I just want to know how to implement option D...
> Can I have you describe your scenario a little bit better? I trying to
> avoid allowing you to go down a path that isn't quite optimal... and I'm
> struggling to come up with a use case for
> setAllowReferenceToSiblingContext. From
> what I can tell, you're flushing a context and one of your Entities has a
> relationship to another Entity that wasn't persisted. If that is the case,
> do you not want the non-persisted Entity to go to the database?
>
> Thanks,
> Rick
>
>
>
>
> On Tue, Feb 12, 2013 at 8:30 AM, Alex <[email protected]> wrote:
>
> > **
> > Rick,
> >
> > Thanks for your reply.
> >
> > I will enhance the entities later. I just want to know how to implement
> > option D...
> >
> > ------------------------------
> > Alex
> >
> >  *From:* Rick Curtis <[email protected]>
> > *Date:* 2013-02-12 22:25
> > *To:* users <[email protected]>; fiiexbl <[email protected]>
> > *Subject:* Re: How to get the reference of StoreContext
> >  First off, you're using openjpa.RuntimeUnenhancedClasses=supported which
> > is not recommended. You'll be much, much happier if you spend the time to
> > set up another enhancement[1] method (build time / javaagent).
> >
> > .... and on to your real question, I think you should be looking at
> > options A or C and ignore option D.
> >
> > Thanks,
> > Rick
> >
> >
> > [1] http://openjpa.apache.org/entity-enhancement.html
> >
> >
> > On Tue, Feb 12, 2013 at 8:14 AM, Alex <[email protected]> wrote:
> >
> >> Hi all,
> >>
> >> I got a below error,
> >>
> >> Caused by: <openjpa-2.2.1-r422266:1396819 nonfatal user error>
> >> org.apache.openjpa.persistence.InvalidStateException: Encountered
> unmanaged
> >> object "org.apache.openjpa.enhance.MEmployee$pcsubclass-670" in life
> cycle
> >> state  unmanaged while cascading persistence via field "MEmployee"
> 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().
> >>
> >> About option D, would someone advise me how to get reference of
> >> StoreContext or it's implementation?
> >>
> >> Thanks in advance.
> >>
> >>
> >>
> >> Alex
> >
> >
> >
> >
> > --
> > *Rick Curtis*
> >
>
>
>
> --
> *Rick Curtis*




-- 
*Rick Curtis*

Reply via email to