You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by Mike Kienenberger <mk...@gmail.com> on 2006/05/23 01:33:57 UTC

Fwd: "Cannot commit changes - channel is not set." after regular DataContext serialization

So I switched from a childDataContext to a regular DataContext, and
now I get a different error :-)

Caused by: org.objectstyle.cayenne.CayenneRuntimeException: [v.1.2B2
April 17 2006] Cannot commit changes - channel is not set.
        at org.objectstyle.cayenne.access.DataContext.flushToParent(DataContext.java:1186)
        at org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:1121)


Something tells me that serialization of DataContexts is a bit rough
right now....

Re: "Cannot commit changes - channel is not set." after regular DataContext serialization

Posted by Mike Kienenberger <mk...@gmail.com>.
On 5/22/06, Mike Kienenberger <mk...@gmail.com> wrote:
> I'm
> currently having an object in my temporary data context with
> relationships to objects in my session-scoped data context.   That's
> not normal, is it?  This particular problem might be caused by how I
> was doing my serialization of DataObjects in the session-scoped data
> context (that context is not serialized, only the objects are).

Yeah, it's looking like this one was a self-inflicted problem.

I threw in some extra code in my base DataObject:

    private void writeObject(java.io.ObjectOutputStream out)
    throws IOException
    {
        out.writeBoolean(Boolean.TRUE ==
this.getDataContext().getUserProperty("temporary"));
        out.defaultWriteObject();
    }
    private void readObject(java.io.ObjectInputStream in)
    throws IOException, ClassNotFoundException
    {
        boolean isInTemporaryDataContext = in.readBoolean();
        in.defaultReadObject();
        this.isInTemporaryDataContext = isInTemporaryDataContext;
    }


and then conditionally attach to the thread-bound datacontext only if
isInTemporaryDataContext is false, and that appears to have solved
this problem.

Re: "Cannot commit changes - channel is not set." after regular DataContext serialization

Posted by Mike Kienenberger <mk...@gmail.com>.
On 5/22/06, Andrus Adamchik <an...@objectstyle.org> wrote:
> If you can reproduce a problem with top-level DC, please log a bug.

Well, it's a bug then.   I don't know if I can simpify it down to a a
trivial test case, though.


> Since objects do not retain DC instance on serialization, I don't see
> how this could happen. Maybe stick a debug statement is
> 'setObjectContext'?

Thanks, I'll take a look.   I do think it's due to my reconnect code
in BaseDataObjectImpl.readResolve() and not a bug in cayenne.  I'm
trying to figure out how to conditionally reattach only if the object
wasn't in my temporary DataContext now.

Re: "Cannot commit changes - channel is not set." after regular DataContext serialization

Posted by Andrus Adamchik <an...@objectstyle.org>.
On May 22, 2006, at 8:52 PM, Mike Kienenberger wrote:

> No.  Lots of DataMaps, but only one DataDomain.

If you can reproduce a problem with top-level DC, please log a bug.


> I'm
> currently having an object in my temporary data context with
> relationships to objects in my session-scoped data context.   That's
> not normal, is it?

No, it is not.

> This particular problem might be caused by how I
> was doing my serialization of DataObjects in the session-scoped data
> context (that context is not serialized, only the objects are).

Since objects do not retain DC instance on serialization, I don't see  
how this could happen. Maybe stick a debug statement is  
'setObjectContext'?

Andrus

Re: "Cannot commit changes - channel is not set." after regular DataContext serialization

Posted by Mike Kienenberger <mk...@gmail.com>.
On 5/22/06, Andrus Adamchik <an...@objectstyle.org> wrote:
> I can imagine that a child context won't reattach to stack properly
> on deserialization (should probably document this as a known
> limitation ... or rather something left to the user to take care of).
> Top level DC however should be able to attach to default DataDomain
> transparently. Do you have more than one DD ?

No.  Lots of DataMaps, but only one DataDomain.

I create like this:

threadDataContext().createDataContext()

And I am explicitly serializing it as follows in another object that
has no other serializable attributes.   I got around the problem by
using setChannel at this point.   Note that this is not really a
childDataContext at this point.

        private void writeObject(java.io.ObjectOutputStream out)
throws IOException
        {
            out.writeObject(this.childDataContext);
        }
        private void readObject(java.io.ObjectInputStream in) throws
IOException, ClassNotFoundException
        {
            this.childDataContext = (DataContext)in.readObject();
            childDataContext.setChannel(super.threadDataContext().getParentDataDomain());
            this.childDataContext.setUserProperty("temporary", Boolean.TRUE);
        }



Seems like every time I work around one issue, two more pop up.  I'm
currently having an object in my temporary data context with
relationships to objects in my session-scoped data context.   That's
not normal, is it?  This particular problem might be caused by how I
was doing my serialization of DataObjects in the session-scoped data
context (that context is not serialized, only the objects are).

Re: "Cannot commit changes - channel is not set." after regular DataContext serialization

Posted by Andrus Adamchik <an...@objectstyle.org>.
I can imagine that a child context won't reattach to stack properly  
on deserialization (should probably document this as a known  
limitation ... or rather something left to the user to take care of).  
Top level DC however should be able to attach to default DataDomain  
transparently. Do you have more than one DD ?

Andrus


On May 22, 2006, at 7:33 PM, Mike Kienenberger wrote:

> So I switched from a childDataContext to a regular DataContext, and
> now I get a different error :-)
>
> Caused by: org.objectstyle.cayenne.CayenneRuntimeException: [v.1.2B2
> April 17 2006] Cannot commit changes - channel is not set.
>        at org.objectstyle.cayenne.access.DataContext.flushToParent 
> (DataContext.java:1186)
>        at org.objectstyle.cayenne.access.DataContext.commitChanges 
> (DataContext.java:1121)
>
>
> Something tells me that serialization of DataContexts is a bit rough
> right now....
>