Re: CayenneRunTimeException when it's sent several requests quickly

From: Mike Kienenberger (mkienen..laska.net)
Date: Mon Mar 15 2004 - 13:31:31 EST

  • Next message: Mike Elliott: "Logging in Cayenne?"

    Jorge Sopena <jsopen..idsa.es> wrote:
    > Hi,
    >
    > I've got a web application using Cayenne as the persistence engine.
    > Apparently everthing goes rigth when I send request one by one.
    > But I'm testing the performance of my app, and I send several requests
    > quickly.
    > All the requests are proccesed but some of the produce this error:
    > CayenneRuntimeException.
    > "Cannot set object as destination of relationship customer
    > because it is in a different DataContext"
    >
    > When does this error happen?, and what could it be the cause?

    Whenever you create a relationship between DataObjects, both objects must be
    in the same DataContext.

    See the following for the official documentation.

    http://www.objectstyle.org/cayenne/userguide/datactxt/moving-objects.html

    Use DataContext.localObjects() to copy an object from another DataContext to
    the current DataContext.
    Or you can use this convenience method to copy a single object.

            public static DataObject getLocalObject(DataContext context, DataObject
    obj)
            {
                    if (null == obj) return null;
                    
                    if (obj.getDataContext() != context)
                    {
                            List localObjectList = context.localObjects(Arrays.asList(new Object[] {
    obj } ));
                            return (DataObject)localObjectList.get(0);
                    }
                    return obj;
            }

    -Mike



    This archive was generated by hypermail 2.0.0 : Mon Mar 15 2004 - 13:31:08 EST