users@glassfish.java.net

Re: ClassCastException

From: Sanjeeb Kumar Sahoo <Sanjeeb.Sahoo_at_Sun.COM>
Date: Tue, 21 Nov 2006 18:11:58 +0530

Hi Stephen,

 From the stack trace, this is what I observe:
There are two EJBs involved here:
/com.rayx.webservices.security.GetUserByNameAndRealmWS/ is a web service
implemented as an EJB end point. In the web method
/getUserByNameAndRealm()/, it invokes
/com.rayx.session.security.SecurityContextRemote.//getUserByNameAndRealm()/
which is a remote business method of an EJB /./ The second EJB uses JPA
and returns com.rayx.presentation.security.GetUserWSResponse object that
wraps the entity beans. The exception is raised in the Web Service EJB
end point while un-marshaling the response object. Is this explanation
correct?

I fail to reproduce this problem. I wrote a very similar app to your's.
During my testing, when I attempt to access one of the lazily fetched
fields which is not populated by the server, I get the rather expected
exception:
/Exception [TOPLINK-7242] (Oracle TopLink Essentials - 9.1 (Build non
promoted: 11/15/2006)):
oracle.toplink.essentials.exceptions.ValidationExceptionException
Description: An attempt was made to traverse a relationship using
indirection that had a null Session. This often occurs when an entity
with an uninstantiated LAZY relationship is serialized and that lazy
relationship is traversed after serialization. To avoid this issue,
instantiate the LAZY relationship prior to serialization./

Have you debugged to find out what class is the object being cast to
that results in ClassCastException? Is it java.io.Serializable? Can you
send us a complete test case or file a bug with a test case?

Thanks,
Sahoo

Marina Vatkina wrote:
> Hi,
>
> I think that the problem is in the class mismatch between the classes
> serialized
> by the container and the classes expected by the client. The TopLink
> Essentials
> as the persistence provider, modified the classes when they were
> loaded, to
> support the fetch type LAZY (do you use it be default or explicitly on
> those
> relationships_. The classes on the client side had not been modified,
> and you
> get a ClassCastException on the de-serialization of the result. If you
> set the
> relationship to null, the class information is (probably) not being
> serialized.
>
> Are you using a Java EE app client as your client? If yes, the
> situation above
> shouldn't happen, and it can be a bug. If not, does switching to an
> appclient
> solves the problem?
>
> thanks,
> -marina
>
> Soe Moe Kyaw @ Stephen Wang wrote:
>> Hi, I think the problem is with my Collection. Please see two
>> attached files.
>>
>> If I put like this;
>>
>> user._setPrincipals(null);
>> user.setCredential(null);
>>
>> user.getRealm()._setUsers(null);
>>
>> I was OK. Is there something wrong?
>>
>> On 11/10/06, Soe Moe Kyaw @ Stephen Wang <swmk.stephen_at_gmail.com> wrote:
>>
>>> Hi, Marina
>>> This doesn't solve the problem.
>>>
>>>
>>> --
>>> Regards;
>>> Stephen Wang
>>>
>>> On 11/9/06, Marina Vatkina wrote:
>>>
>>> Hi Stephen,
>>>
>>> I think that the problem is in the classes on the client side that
>>> were not
>>> processed by the TopLink code. Can you check that marking all ToOne
>>> relationships with fetch type EAGER solves the problem?
>>>
>>> thanks,
>>> -marina
>>>
>>> Soe Moe Kyaw @ Stephen Wang wrote:
>>> > java.lang.ClassCastException:
>>> > com.rayx.presentation.security.GetUserWSResponse
>>> > at
>>> > com.sun.corba.ee.impl.copyobject.ORBStreamObjectCopierImpl.copy(
>>> ORBStreamObjectCopierImpl.java:43)
>>> > at
>>> > com.sun.corba.ee.impl.copyobject.ORBStreamObjectCopierImpl.copy
>>> > (ORBStreamObjectCopierImpl.java:32)
>>> > at
>>> > com.sun.corba.ee.impl.copyobject.FallbackObjectCopierImpl.copy(
>>> FallbackObjectCopierImpl.java:39)
>>> > at
>>> > com.sun.corba.ee.impl.copyobject.FallbackObjectCopierImpl.copy
>>> > (FallbackObjectCopierImpl.java:30)
>>> > at
>>> > com.sun.corba.ee.impl.javax.rmi.CORBA.Util.copyObject(Util.java:745)
>>> > at
>>> > com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshall
>>> erImpl.copyResult(DynamicMethodMarshallerImpl.java
>>> > :414)
>>> > at
>>> > com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandler
>>> Impl.privateInvoke(StubInvocationHandlerImpl.java:202)
>>> > at
>>> >
>>> com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(
>>>
>>> > StubInvocationHandlerImpl.java:119)
>>> > at
>>> > com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(
>>> BCELStubBase.java:197)
>>> > at
>>> > com.rayx.session.security.__SecurityContextRemote_Remote
>>> _DynamicStub.getUserByNameAndRealm
>>> > (__SecurityContextRemote_Remote_DynamicStub.java)
>>> > at
>>> > com.rayx.session.security._SecurityContextRemote_Wrapper
>>> .getUserByNameAndRealm(com.rayx.session.security.
>>> _SecurityContextRemote_Wrapper.java)
>>> > at
>>> > com.rayx.webservices.security.GetUserByNameAndRealmWS
>>> .getUserByNameAndRealm
>>> > (GetUserByNameAndRealmWS.java:72)
>>> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>> > at
>>> >
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java
>>>
>>> :39)
>>> > at sun.reflect.DelegatingMethodAccessorImpl.invoke
>>> > (DelegatingMethodAccessorImpl.java:25)
>>> > at java.lang.reflect.Method.invoke(Method.java:585)
>>> > at
>>> > com.sun.enterprise.security.application.EJBSecurityManager.runMethod(
>>> EJBSecurityManager.java:1050)
>>> > at
>>> >
>>> com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:165)
>>> > at
>>> > com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(
>>> BaseContainer.java:2766)
>>> > at com.sun.ejb.containers.BaseContainer.intercept
>>> > (BaseContainer.java:3847)
>>> > at
>>> > com.sun.ejb.containers.WebServiceInvocationHandler.invoke
>>> (WebServiceInvocationHandler.java:147)
>>> > at $Proxy47.getUserByNameAndRealm(Unknown Source)
>>> > at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
>>> > at
>>> >
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java
>>>
>>> :39)
>>> > at
>>> > sun.reflect.DelegatingMethodAccessorImpl.invoke
>>> (DelegatingMethodAccessorImpl.java:25)
>>> > at java.lang.reflect.Method.invoke(Method.java:585)
>>> > at com.sun.xml.ws.server.PeptTie._invoke(PeptTie.java:61)
>>> > at
>>> >
>>> com.sun.xml.ws.protocol.soap.server.SOAPMessageDispatcher.invokeEndpoint(
>>>
>>> SOAPMessageDispatcher.java
>>> > :280)
>>> > at
>>> > com.sun.xml.ws.protocol.soap.server.SOAPMessageDispatcher
>>> $SoapInvoker.invoke(SOAPMessageDispatcher.java:588)
>>> > at
>>> > com.sun.xml.ws.protocol.soap.server.SOAPMessageDispatcher.receive(
>>> SOAPMessageDispatcher.java
>>> > :147)
>>> > at com.sun.xml.ws.server.Tie.handle(Tie.java:90)
>>> > at
>>> > com.sun.enterprise.webservice.Ejb3MessageDispatcher.handlePost(
>>> Ejb3MessageDispatcher.java:160)
>>> > at com.sun.enterprise.webservice.Ejb3MessageDispatcher.invoke
>>> > (Ejb3MessageDispatcher.java:89)
>>> > at
>>> >
>>> com.sun.enterprise.webservice.EjbWebServiceServlet.dispatchToEjbEndpoint(
>>>
>>> EjbWebServiceServlet.java:186)
>>> > at com.sun.enterprise.webservice.EjbWebServiceServlet.service
>>> > (EjbWebServiceServlet.java:117)
>>> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
>>> > at
>>> >
>>> com.sun.enterprise.web.AdHocContextValve.invoke(AdHocContextValve.java
>>> :101)
>>> > at org.apache.catalina.core.StandardPipeline.doInvoke
>>> > (StandardPipeline.java:566)
>>> > at
>>> >
>>> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java
>>> :536)
>>> > at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:71)
>>> > at org.apache.catalina.core.StandardHostValve.invoke
>>> > (StandardHostValve.java:182)
>>> > at
>>> >
>>> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java
>>>
>>> :566)
>>> > at
>>> > com.sun.enterprise.web.VirtualServerPipeline.invoke(
>>> VirtualServerPipeline.java:120)
>>> > at
>>> > org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
>>> > at
>>> > org.apache.catalina.core.StandardEngineValve.invoke(
>>> StandardEngineValve.java:137)
>>> > at org.apache.catalina.core.StandardPipeline.doInvoke
>>> > (StandardPipeline.java:566)
>>> > at
>>> >
>>> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java
>>> :536)
>>> > at
>>> > org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
>>> > at org.apache.coyote.tomcat5.CoyoteAdapter.service
>>> > (CoyoteAdapter.java:239)
>>> > at
>>> > com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(
>>> ProcessorTask.java:667)
>>> > at
>>> >
>>> com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(
>>>
>>> ProcessorTask.java
>>> > :574)
>>> > at
>>> > com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(
>>> ProcessorTask.java:844)
>>> > at
>>> >
>>> com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(
>>> ReadTask.java:287)
>>> > at
>>> >
>>> com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java
>>> :212)
>>> > at
>>> >
>>> com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
>>>
>>> > at com.sun.enterprise.web.connector.grizzly.WorkerThread.run
>>> > (WorkerThread.java:75)
>>> >
>>> > --
>>> > Regards;
>>> > Stephen Wang
>>> >
>>> > On 11/9/06, Marina Vatkina wrote:
>>> >
>>> > What is the exact exception text?
>>> >
>>> > thanks,
>>> > -marina
>>> >
>>> > Soe Moe Kyaw @ Stephen Wang wrote:
>>> >> I do have two toplinks jar in my SDKlib but not in my domain lib.
>>> >> Sure, I can give you more on what you wanna know. What shall I give?
>>> >>
>>> >> --
>>> >> Regards;
>>> >> Soe Moe Kyaw @ Stephen Wang
>>> >>
>>> >> On 11/8/06, Marina Vatkina wrote:
>>> >>
>>> >> Hi,
>>> >>
>>> >> Do you have toplink-essentials.jar on the web side of your
>>> > app? If not,
>>> >> please try to add it and check if it solves the problem. If
>>> > you do,
>>> >> we need
>>> >> more details to be able to help.
>>> >>
>>> >> thanks,
>>> >> -marina
>>> >>
>>> >> Soe Moe Kyaw @ Stephen Wang wrote:
>>> >> > This happens like this;
>>> >> >
>>> >> > I have Entities namly User, Realm, Credential and Principal.
>>> >> >
>>> >> > User is associated with Realm (Many-to-One), Credential
>>> >> (One-to-One),
>>> >> > Principal (One-to-Many).
>>> >> >
>>> >> > I have a web service called getUserByNameAndRealm which takes user
>>> >> name
>>> >> > and realm name. That web method delegate to a method from Session
>>> >> > Bean. The result is wrapped by a Class which includes User and
>>> >> Status
>>> >> > of the operation. It works well when the session returns the
>>> > response
>>> >> > which User object is null. But when the session found the User and
>>> >> > returns it, the Exception occured. So I tried to set the
>>> principal,
>>> >> > credential and realm of User to null. It works well then. Why
>>> >> does it
>>> >> > happen like that and any solution to that?
>>> >> >
>>> >>
>>> >>
>>> > ---------------------------------------------------------------------
>>> >> To unsubscribe, e-mail:
>>> > users-unsubscribe_at_glassfish.dev.java.net
>>> > <mailto:users-unsubscribe_at_glassfish.dev.java.net>
>>> > > <mailto:users-unsubscribe_at_glassfish.dev.java.net
>>> > <mailto:users-unsubscribe_at_glassfish.dev.java.net>>
>>> >> For additional commands, e-mail: users-help_at_glassfish.dev.java
>>> > .net <mailto:users-help_at_glassfish.dev.java.net>
>>> > > <mailto:users-help_at_glassfish.dev.java.net
>>> > <mailto:users-help_at_glassfish.dev.java.net>>
>>> >>
>>> >
>>> > ---------------------------------------------------------------------
>>> > To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>>> > <mailto:users-unsubscribe_at_glassfish.dev.java.net>
>>> > For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>> > <mailto:users-help_at_glassfish.dev.java.net>
>>> >
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>>
>>>
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>