You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by John <mm...@web.de> on 2006/11/01 19:39:38 UTC

Using Cayenne withTomcat gives ClassCastException

Hello,
I use Cayenne with Tapestry and tomcat.

I fetch data from the DB using Cayenne The application runs well until I make change on the Java file like Home.java I have to restart TOMCAT new. Restarting the Application doesnot solve the problem.
Changing the Home.page or Home.html does not create the error.
The error i get is:
------------------------------------------------------------------------
      java.lang.ClassCastException 
      de.model.MenuObject cannot be cast to de.model.MenuObject 

------------------------------------------------------------------------

Anybody knows why or how can i solve this?

I face this problem only with Cayenne, cos using a sample List does not creates this effect.

Thx in advance.

Re: Using Cayenne withTomcat gives ClassCastException

Posted by Juergen Saar <ju...@jsaar.org>.
even if the BusinessObjects are compiled with a different version of cayenne
as used in tomcat, there are strange runtime-errors ...

2006/11/2, Cris Daniluk <cr...@gmail.com>:
>
> > > This seems like some kind of classloader issue. John need to make
> > > sure that cayenne.jar is loaded by the same classloader as the app
> > > code. In most simple case this means putting it in the war. But there
> > > are more weird cases such as this one:
> > >
> >
> > Hi thanks for answering,
> > You are right, i use diffrent Cayenne.jarS.
> >
>
> You mean, you have more than one cayenne.jar on the classpath? That
> would be your problem... because Tomcat uses nested classloaders, you
> can run into problems like this:
>
> java.lang.ClassCastException
>      de.model.MenuObject cannot be cast to de.model.MenuObject
>
> .. very easily.
>
> Cris
>

Re: Using Cayenne withTomcat gives ClassCastException

Posted by Cris Daniluk <cr...@gmail.com>.
On 11/2/06, John <mm...@web.de> wrote:
> Hello Cris,
> No you misunderstood me.
> I develop with Eclipse and I have or (HAD) a Cayenne.jar under my
> "ThierdpartyJars". And another Cayenne.jar for "./tomcat/shared/lib/" and
> when i start the application using Tomcat and Tomcat uses the shared jars.
>
> however, NOW: i use the same Jars under "./tomcat/shared/lib/" and I still
> have the same problem.
> as soon as I change any part from Home.jave I have to restart TomCat
> completely.
>

I still may not quite be there... if you're using Eclipse with WTP, it
may be deploying your other cayenne.jar on your behalf, so you could
still have both in Tomcat's classpath.

However, if you're simply saying that when you change a class while
Tomcat is running and encounter this problem on redelpoy - I'm not
surprised. Putting jars under tomcat/shared/lib is asking for this
problem to happen.

Cris

Re: Using Cayenne withTomcat gives ClassCastException

Posted by John <mm...@web.de>.
Hello Cris,
No you misunderstood me.
I develop with Eclipse and I have or (HAD) a Cayenne.jar under my 
"ThierdpartyJars". And another Cayenne.jar for "./tomcat/shared/lib/" and 
when i start the application using Tomcat and Tomcat uses the shared jars.

however, NOW: i use the same Jars under "./tomcat/shared/lib/" and I still 
have the same problem.
as soon as I change any part from Home.jave I have to restart TomCat 
completely.

Thanks for your answers in advance. I still need help :)

John.
Regards.


----- Original Message ----- 
From: "Cris Daniluk" <cr...@gmail.com>
To: <ca...@incubator.apache.org>
Sent: Thursday, November 02, 2006 1:18 AM
Subject: Re: Using Cayenne withTomcat gives ClassCastException


>> > This seems like some kind of classloader issue. John need to make
>> > sure that cayenne.jar is loaded by the same classloader as the app
>> > code. In most simple case this means putting it in the war. But there
>> > are more weird cases such as this one:
>> >
>>
>> Hi thanks for answering,
>> You are right, i use diffrent Cayenne.jarS.
>>
>
> You mean, you have more than one cayenne.jar on the classpath? That
> would be your problem... because Tomcat uses nested classloaders, you
> can run into problems like this:
>
> java.lang.ClassCastException
>     de.model.MenuObject cannot be cast to de.model.MenuObject
>
> .. very easily.
>
> Cris
> 


Re: Using Cayenne withTomcat gives ClassCastException

Posted by Cris Daniluk <cr...@gmail.com>.
> > This seems like some kind of classloader issue. John need to make
> > sure that cayenne.jar is loaded by the same classloader as the app
> > code. In most simple case this means putting it in the war. But there
> > are more weird cases such as this one:
> >
>
> Hi thanks for answering,
> You are right, i use diffrent Cayenne.jarS.
>

You mean, you have more than one cayenne.jar on the classpath? That
would be your problem... because Tomcat uses nested classloaders, you
can run into problems like this:

java.lang.ClassCastException
     de.model.MenuObject cannot be cast to de.model.MenuObject

.. very easily.

Cris

Re: Using Cayenne withTomcat gives ClassCastException

Posted by John <mm...@web.de>.
----- Original Message ----- 
From: "Andrus Adamchik" <an...@objectstyle.org>
To: <ca...@incubator.apache.org>
Sent: Wednesday, November 01, 2006 9:01 PM
Subject: Re: Using Cayenne withTomcat gives ClassCastException


> This seems like some kind of classloader issue. John need to make  
> sure that cayenne.jar is loaded by the same classloader as the app  
> code. In most simple case this means putting it in the war. But there  
> are more weird cases such as this one:
> 

Hi thanks for answering,
You are right, i use diffrent Cayenne.jarS.





> http://objectstyle.org/cayenne/lists/cayenne-user/2006/10/0063.html
> 
> (also is there a WO framework involved here?? If so I can't give  
> specific advice, other than debugging ClassLoader hierarchy)
No No WO frameworks at all.


> 
> Andrus
> 
> 
> On Nov 1, 2006, at 2:54 PM, Michael Gentry wrote:
> 
>> I never got that when I used Tomcat with Tapestry.  How are you
>> starting Tomcat up?  I always used the Tomcat plugin for Eclipse and
>> it worked pretty well.  Another option for development is to use
>> Jetty/Jetty Launcher/Eclipse.  Jetty starts up much faster.  As for
>> hot code replacement, it works pretty well as long as I edit inside a
>> method.  It fails if I add class instance variables or modify the
>> method's signature.
>>
>> /dev/mrg
>>
>>
>> On 11/1/06, John <mm...@web.de> wrote:
>>> Hello,
>>> I use Cayenne with Tapestry and tomcat.
>>>
>>> I fetch data from the DB using Cayenne The application runs well  
>>> until I make change on the Java file like Home.java I have to  
>>> restart TOMCAT new. Restarting the Application doesnot solve the  
>>> problem.
>>> Changing the Home.page or Home.html does not create the error.
>>> The error i get is:
>>> --------------------------------------------------------------------- 
>>> ---
>>>       java.lang.ClassCastException
>>>       de.model.MenuObject cannot be cast to de.model.MenuObject
>>>
>>> --------------------------------------------------------------------- 
>>> ---
>>>
>>> Anybody knows why or how can i solve this?
>>>
>>> I face this problem only with Cayenne, cos using a sample List  
>>> does not creates this effect.
>>>
>>> Thx in advance.
>>>
>>>
>>
> 
>

Re: Using Cayenne withTomcat gives ClassCastException

Posted by Andrus Adamchik <an...@objectstyle.org>.
Ok, looks like no WO is involved (just reread the original message -  
doh!). Still the advice given in the quoted thread on how to compare  
the classloaders should help to debug the problem.

Andrus

On Nov 1, 2006, at 3:01 PM, Andrus Adamchik wrote:
> This seems like some kind of classloader issue. John need to make  
> sure that cayenne.jar is loaded by the same classloader as the app  
> code. In most simple case this means putting it in the war. But  
> there are more weird cases such as this one:
>
> http://objectstyle.org/cayenne/lists/cayenne-user/2006/10/0063.html
>
> (also is there a WO framework involved here?? If so I can't give  
> specific advice, other than debugging ClassLoader hierarchy)
>
> Andrus
>
>
> On Nov 1, 2006, at 2:54 PM, Michael Gentry wrote:
>
>> I never got that when I used Tomcat with Tapestry.  How are you
>> starting Tomcat up?  I always used the Tomcat plugin for Eclipse and
>> it worked pretty well.  Another option for development is to use
>> Jetty/Jetty Launcher/Eclipse.  Jetty starts up much faster.  As for
>> hot code replacement, it works pretty well as long as I edit inside a
>> method.  It fails if I add class instance variables or modify the
>> method's signature.
>>
>> /dev/mrg
>>
>>
>> On 11/1/06, John <mm...@web.de> wrote:
>>> Hello,
>>> I use Cayenne with Tapestry and tomcat.
>>>
>>> I fetch data from the DB using Cayenne The application runs well  
>>> until I make change on the Java file like Home.java I have to  
>>> restart TOMCAT new. Restarting the Application doesnot solve the  
>>> problem.
>>> Changing the Home.page or Home.html does not create the error.
>>> The error i get is:
>>> -------------------------------------------------------------------- 
>>> ----
>>>       java.lang.ClassCastException
>>>       de.model.MenuObject cannot be cast to de.model.MenuObject
>>>
>>> -------------------------------------------------------------------- 
>>> ----
>>>
>>> Anybody knows why or how can i solve this?
>>>
>>> I face this problem only with Cayenne, cos using a sample List  
>>> does not creates this effect.
>>>
>>> Thx in advance.
>>>
>>>
>>
>
>


Re: Using Cayenne withTomcat gives ClassCastException

Posted by Andrus Adamchik <an...@objectstyle.org>.
This seems like some kind of classloader issue. John need to make  
sure that cayenne.jar is loaded by the same classloader as the app  
code. In most simple case this means putting it in the war. But there  
are more weird cases such as this one:

http://objectstyle.org/cayenne/lists/cayenne-user/2006/10/0063.html

(also is there a WO framework involved here?? If so I can't give  
specific advice, other than debugging ClassLoader hierarchy)

Andrus


On Nov 1, 2006, at 2:54 PM, Michael Gentry wrote:

> I never got that when I used Tomcat with Tapestry.  How are you
> starting Tomcat up?  I always used the Tomcat plugin for Eclipse and
> it worked pretty well.  Another option for development is to use
> Jetty/Jetty Launcher/Eclipse.  Jetty starts up much faster.  As for
> hot code replacement, it works pretty well as long as I edit inside a
> method.  It fails if I add class instance variables or modify the
> method's signature.
>
> /dev/mrg
>
>
> On 11/1/06, John <mm...@web.de> wrote:
>> Hello,
>> I use Cayenne with Tapestry and tomcat.
>>
>> I fetch data from the DB using Cayenne The application runs well  
>> until I make change on the Java file like Home.java I have to  
>> restart TOMCAT new. Restarting the Application doesnot solve the  
>> problem.
>> Changing the Home.page or Home.html does not create the error.
>> The error i get is:
>> --------------------------------------------------------------------- 
>> ---
>>       java.lang.ClassCastException
>>       de.model.MenuObject cannot be cast to de.model.MenuObject
>>
>> --------------------------------------------------------------------- 
>> ---
>>
>> Anybody knows why or how can i solve this?
>>
>> I face this problem only with Cayenne, cos using a sample List  
>> does not creates this effect.
>>
>> Thx in advance.
>>
>>
>


Re: Using Cayenne withTomcat gives ClassCastException

Posted by Michael Gentry <bl...@gmail.com>.
I never got that when I used Tomcat with Tapestry.  How are you
starting Tomcat up?  I always used the Tomcat plugin for Eclipse and
it worked pretty well.  Another option for development is to use
Jetty/Jetty Launcher/Eclipse.  Jetty starts up much faster.  As for
hot code replacement, it works pretty well as long as I edit inside a
method.  It fails if I add class instance variables or modify the
method's signature.

/dev/mrg


On 11/1/06, John <mm...@web.de> wrote:
> Hello,
> I use Cayenne with Tapestry and tomcat.
>
> I fetch data from the DB using Cayenne The application runs well until I make change on the Java file like Home.java I have to restart TOMCAT new. Restarting the Application doesnot solve the problem.
> Changing the Home.page or Home.html does not create the error.
> The error i get is:
> ------------------------------------------------------------------------
>       java.lang.ClassCastException
>       de.model.MenuObject cannot be cast to de.model.MenuObject
>
> ------------------------------------------------------------------------
>
> Anybody knows why or how can i solve this?
>
> I face this problem only with Cayenne, cos using a sample List does not creates this effect.
>
> Thx in advance.
>
>