We need help getting this to work again. I think that there are some basic 
concepts around this that we are missing like: 
Is it supposed to be possible to have two web apps in the same tomcat both use 
Cayenne at all?
Is it supposed to be possible to have two web apps in the same tomcat both use 
Cayenne access the same data and/or use the same java classes?
If it is supposed to be possible, what are the challenges in doing it?
What are the preferred methods for overcoming those challenges?
Is there anything I should be reading about this?
Are we supposed to be dealing with multiple class loaders? if so, what do we 
need to do to deal with them?
What changed in Cayenne and/or Tomcat relevant to this since Cayenne version 
1.1 and Tomcat 4.0.6? 
Thanks! 
Eric
--- On Fri, 9/10/10, Eric Lazarus <[email protected]> wrote:

From: Eric Lazarus <[email protected]>
Subject: Re: Using Cayenne in two different webapps in the same TomCat instance
To: [email protected]
Date: Friday, September 10, 2010, 4:32 PM

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 <[email protected]> wrote:

From: Tore Halset <[email protected]>
Subject: Re: Using Cayenne in two different webapps in the same TomCat instance
To: [email protected]
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).



      


      

Reply via email to