Re: Using Cayenne in two different webapps in the same TomCat instance

From: Mike Kienenberger (mkienen..mail.com)
Date: Fri Sep 10 2010 - 22:42:34 UTC

  • Next message: Andrus Adamchik: "Re: cayenne-ANT : package org.apache.cayenne does not exist"

    Probably the best thing to do is to create a simple program that does
    the classloader lookup for you and print out each instance that is
    found.

    I know for instance under jetty 6.1 that certain classloader resource
    calls find the same resource twice, and this can help you find out if
    the resource is really only in one place, in multiple places, or
    nowhere to be find.

    On Fri, Sep 10, 2010 at 4:32 PM, Eric Lazarus <ericllazaru..ahoo.com> wrote:
    > Yes, I was using a common copy of the cayenne-server.jar for both webapps. It was not in any of the standard tomcat directories, but had a custom location configured in catalina.properties for the 'common' classloader.
    > I removed this entry in catalina-properties, and put all the cayenne jar filesinto WEB-INF/lib, a separate copy for each webapp.
    > The ClassCastException went away, but a new Exception took its place.Again, either webapp works fine unless the other one was accessed previously.
    > The new problem is a java.lang.NoSuchFieldExceptionin org.apache.cayenne.reflect.FieldAccessor.lookupFieldInHierarchy.
    > The field mentioned is one of the static "_PROPERTY" fields generated by cayenne, and really should exist. So, I suspect that the problem is with the class loader, rather than the data map. Like the other problem, this happens on the very first query.
    > So, now /home/clipper/4000/app/jsp/WEB-INF/lib for the main application and /home/clipper/4000/pcsWEB-INF/lib now but in the past I had it only in  /usr/local/lib/cayenne/3.0.
    > Eric
    >
    > --- On Fri, 9/10/10, Tore Halset <halse..vv.ntnu.no> wrote:
    >
    > From: Tore Halset <halse..vv.ntnu.no>
    > Subject: Re: Using Cayenne in two different webapps in the same TomCat instance
    > To: use..ayenne.apache.org
    > Date: Friday, September 10, 2010, 9:03 AM
    >
    > Hello.
    >
    > On Sep 10, 2010, at 00:21 , Eric Lazarus wrote:
    >
    >> We are using cayenne 3.0M6 and Tomcat 6.0.20. (We used to use Cayenne 1.1 and Tomcat 4.0.6 without this issue showing up.)
    >> The problem occurs when we access one of the web apps then the other, in either order. If you access the first webapp and then access the second (or vice versa) you get a peculiar ClassCastException which says that an object returned from a cayenne querycannot be cast to the class that we expect to be able to cast it to.
    >
    > Where is the cayenne-server.jar? Is it in one of the lib-folders of tomcat or inside your webapp?
    >
    > Regards,
    >  - Tore.
    >
    > Using cayenne in two different webapps in the same TomCat instance
    > Is it OK to have two different cayenne-based webapps in the same TomCat both use the same source code and the same database? If so, what do we need to do to allow this to work?
    > We have an application that consists of 2 webapps that run in the same tomcat instance.
    > The share the same code via symlinks in the source code base. There are 2 webapps because one of them needs to be password protected and the other needs to be publicly available.
    > We are using cayenne 3.0M6 and Tomcat 6.0.20. (We used to use Cayenne 1.1 and Tomcat 4.0.6 without this issue showing up.)
    > The problem occurs when we access one of the web apps then the other, in either order. If you access the first webapp and then access the second (or vice versa) you get a peculiar ClassCastException which says that an object returned from a cayenne querycannot be cast to the class that we expect to be able to cast it to.
    > We get the problem the right away, in our attempt to get ahold of the object that represents the current user which is a root that we use to fault in lots of other objects.
    > It seems that we end up with two different class loaders, perhaps one for each webapp?
    > When you examine the offending object you find that:     object.getClass().getName()  == "main.SystemUser"BUT  object.getClass().hashCode() != main.SystemUser.class.hashCode()
    > You also find that:     object.getClass().getClassLoader().toString() == main.SystemUser.class.getClassLoader().toString()   BUT object.getClass().getClassLoader().hashCode() != main.SystemUser.class.getClassLoader().hashCode()
    >  In each case getClassLoader().toString() == org.apache.catalina.loader.WebappClassLoader,                                             delegate: false, repositories: /WEB-INF/classes
    > This seems to indicate that cayenne is returning objects constructed using two different instances of the WebappClassLoader, perhaps each assocated with a different class loader.
    > Our application previously used Cayenne 1.1 and we don't think that this happened, perhaps because a separate instance was created for each webapp, but cayenne 3.0 is trying to share (or something like that).
    >
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Fri Sep 10 2010 - 22:43:39 UTC