Re: different ObjectContext...

From: Arnaud Garcia (arnau..magemed-87.com)
Date: Sat Apr 24 2010 - 08:03:58 EDT

  • Next message: Arnaud Garcia: "Re: Wicket Cayenne"

    Thank you so much !
    I was start reading to switch to hibernate, since there is a good
    documentation for wicket integration...
    Hopefully, with your answers I can still using Cayenne !

    Arnaud

    2010/4/24 Nishant Neeraj <nishant.has.a.questio..mail.com>

    > Hi Arnaud,
    >
    > Sorry, did not see this post earlier.
    > We stumbled on this problem, especially when playing with browser back
    > button.
    > I am not sure if de-serialization causes re-bind of the Context to
    > different
    > thread... specially when we have session level DataContext that stays alive
    > across the pages.
    >
    > Anyways, I did a work around for this. I wrote a LoadableDetachable type of
    > IModel that performs
    >
    > [CODE]
    > public T getObject() {
    > if (this.object == null) {
    > if (this.objectId != null) {
    > this.object = load(objectId);
    > if (this.object == null) {
    > throw new MyRuntimeException("Entity not found. Id: "
    > + this.objectId);
    > }
    > }
    > }
    >
    > if (this.object != null
    > && ((DataObject) object).getPersistenceState() ==
    > PersistenceState.HOLLOW
    > && this.objectId != null) {
    > this.object = load(this.objectId);
    > }
    >
    > return this.object;
    > }
    >
    > [/CODE]
    >
    >
    > And load is something like this
    >
    > [CODE]
    > private T load(ObjectId objId) {
    > DataContext ctx = ((CayenneORMInterface) EduShareSession.get()
    > .getSessionORMInterface()).getDataContext();
    > DataObject dobj = (DataObject) DataObjectUtils.objectForPK(ctx,
    > objId);
    > return (T) dobj;
    > }
    > [/CODE]
    >
    > This works most of the cases.
    >
    > However, I am still looking for a better solution because if you perform
    > DataContext.newObject(...) -- the object, when serialized without
    > DataContext.commitChanges() -- does not hold a permanentId (temporary
    > object
    > ID is not much help). And you can't ask Cayenne to resurrect this from
    > Cache
    > based on temporaryId.
    >
    >
    > Hopefully this helps. Suggestions welcome.
    >
    > - Nishant
    >
    > On Fri, Apr 23, 2010 at 12:43 AM, Arnaud Garcia <arnau..magemed-87.com
    > >wrote:
    >
    > > Hello,
    > > (lot of questions today ;-)
    > >
    > > I have a curious error on my site (wicket+cayenne).
    > >
    > > Cannot set object as destination of relationship toAdresse because it is
    > in
    > > a different ObjectContext
    > > at
    > >
    > >
    > org.apache.cayenne.CayenneDataObject.willConnect(CayenneDataObject.java:344)
    > > at
    > >
    > >
    > org.apache.cayenne.CayenneDataObject.setToOneTarget(CayenneDataObject.java:298)
    > >
    > >
    > >
    > > How a cayenne object can be in a different context ? (In my understanding
    > a
    > > Context is attached to the current thread, so different ObjectContext
    > means
    > > different threads)
    > >
    > > Is it possible that the Wicket serialize/de-serialize mechanism create a
    > > new re-bind of the Context to another thread ??
    > > there was a similar discussion 2 weeks ago:
    > >
    > >
    > http://cayenne.195.n3.nabble.com/Conditions-when-PersistenceState-gets-hollow-tp691334p692371.html
    > >
    > >
    > > thanks
    > >
    > > Arnaud
    > >
    >



    This archive was generated by hypermail 2.0.0 : Sat Apr 24 2010 - 08:04:37 EDT