cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Lazarus <>
Subject Using Cayenne in two different webapps in the same TomCat instance
Date Thu, 09 Sep 2010 22:21:45 GMT
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:
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).

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message