wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes ClassCastException for Stateful Bean in JBoss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "ClassCastException for Stateful Bean in JBoss" Watch "ClassCastException for Stateful Bean in JBoss" New topic
Author

ClassCastException for Stateful Bean in JBoss

hashmukh punamia
Greenhorn

Joined: Aug 14, 2007
Posts: 22
Hi Reza and other Ranchers,

I am facing some issue in Stateful Session Bean in JBoss.

This is my SessionBean code




The following Code in my client calls the bean



I get the following error.
java.lang.ClassCastException: $Proxy169

I also checked the classpath and everything and they seems to be fine.
Also if I change the @Stateful to @Stateless, it works fine

Is this the issue with the JBoss4.2.2GA version.

Your Help would be appreciated.

Thanks in advance.

Regerds,
Hash
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
try to change your Bean code to like this-

@Stateful(name = "SampleStatefulEJBA", mappedName="java:comp/env/SampleStatefulEJBA")


SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
hashmukh punamia
Greenhorn

Joined: Aug 14, 2007
Posts: 22
HI AmanDeep,

I am still getting the same Error.

java.lang.ClassCastException: $Proxy71

any other solutions for this issue

Thanks,
Hash
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Hash,

This does look like a class-path issue. I would look closely to see if you have multiple copies of any class/interface in the classpath. If so, you'll need to remove them and set module depenencies correctly.

Best regards,
Reza


Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9943
    
159

hashmukh,

As Reza mentioned, check whether you are packaging the bean interfaces in more than one place - one in jar and one in war. If so, then remove it from the war and let it remain in the jar.

Also if I change the @Stateful to @Stateless, it works fine


That's interesting. Which JDK version do you use? And do you use any IDE (like NetBeans) with JBoss? I remember something similar with NetBeans and JBoss with Java 1.6


[My Blog] [JavaRanch Journal]
hashmukh punamia
Greenhorn

Joined: Aug 14, 2007
Posts: 22
Hi Reza and Pai,

Thanks for your quick reply.

I am using Netbeans6.1RC2 to create a independant EJB module with the stateless bean code as shown in the above message. My EJB module only consists of a sample Bean and a the Bean Interface.
Then I deploy the ejb module in JBoss4.2.2GA.

Now I create a seperate web application project to which I have added this ejb jar file to my project lib.
I am importing the package into my JSP and just doing a lookup for the same.

But I am getting java.lang.ClassCastException: $Proxy108

Thanks in advance

Thanks,
Hash
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Hash,

You cannot copy the ejb-jar file directly. You must properly reference it as a Java EE module via manifest class path dependency. Again, feel free to take a look at our JBoss code examples.

Best regards,
Reza
hashmukh punamia
Greenhorn

Joined: Aug 14, 2007
Posts: 22
Hi Reza, JaiKiran and AmanDeep,

Finally Its is working.

Thanks a lot.

Thanks & Regards,
Hash
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassCastException for Stateful Bean in JBoss
 
Similar Threads
ETS Question doubts
Resource injection for env entry in the field
Stateful bean cache
Error when trying to use an extended persistence context in EJB 3
Stateful bean cache