Stateful EJB3.0 查询返回问题

08-04-05 colingo
Exception in thread "main" java.lang.NoClassDefFoundError: Lorg/hibernate/type/AbstractComponentType;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
at java.lang.Class.getDeclaredField(Class.java:1880)
at java.io.ObjectStreamClass.getDeclaredSUID(ObjectStreamClass.java:1610)
at java.io.ObjectStreamClass.access$700(ObjectStreamClass.java:52)
at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:425)
at java.security.AccessController.doPrivileged(Native Method)
at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:413)
at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:310)
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:547)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1583)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1945)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1869)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at org.jboss.aop.joinpoint.InvocationResponse.readExternal(InvocationResponse.java:122)
at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1792)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1945)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1869)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObjectVersion2_2(JavaSerializationManager.java:239)
at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:133)
at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:120)
at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.versionedRead(MicroSocketClientInvoker.java:957)
at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:586)
at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:122)
at org.jboss.remoting.Client.invoke(Client.java:1634)
at org.jboss.remoting.Client.invoke(Client.java:548)
at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:62)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:67)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateful.StatefulRemoteProxy.invoke(StatefulRemoteProxy.java:139)
at $Proxy2.findOrCreateCustomer(Unknown Source)
at com.titan.client.Client.testStatefull(Client.java:120)
at com.titan.client.Client.main(Client.java:66)

[该贴被xinying_ge于2008-04-05 14:51修改过]

colingo
2008-04-05 14:52
接口中的方法
public Customer findOrCreateCustomer(String firstName,String lastName);
agent是在客户端的一远程接口
如下查询是
agent.findOrCreateCustomer("Zhang", "Y");
没有出错,而且能正常运行
但是改成这样
Customer cus = agent.findOrCreateCustomer("Zhang", "Y");
就出错了,错误信息如上

[该贴被xinying_ge于2008-04-05 14:53修改过]

colingo
2008-04-05 15:37
经过测试发现,原来是我的Customer中fetch = FetchType.LAZY的原因.
我把这个去掉,就正常了?
为什么会这样呢?不明白!

banq
2008-04-05 15:37
估计查询返回的类型有问题

>java.lang.NoClassDefFoundError: Lorg/hibernate/type/AbstractComponentType
org/hibernate/type/AbstractComponentType所在包可能有两个,导致版本不一致。

colingo
2008-04-05 15:58
我查了一下,不是两个有AbstractComponentType的包!应该不是这个原因.

colingo
2008-04-05 16:12
Banq,
我把Customer中的fetch = FetchType=LAZY去掉后就正常了.
因为,findOrCreate方法是这样的:将从SessionBean中查询到或是没有查询到的用name创建一个新的实例保存起来,然后返回.
我记得以前用Hibernate中,如果一个对象是处于游离状态,此时要用它获取与之相关联的实体是,会抛异常.
你看能不能这样解释,因为findOrCreate方法是从SessionBean中返回到过程客户端一个实例,也就是说,返回到客户端时,它已经是处于游离状态,如果用它获取与之相关联的对象肯定会出错.是不是为了避免这个问题发生,它就直接不让你返回一个具体的实例:Customer customer = agent.findOrCreate(...)(只是它的表现形式为返回一个具体实例时就出错).而agent.findOrCreate(...)就不出错.
可以这样解释吗?

[该贴被xinying_ge于2008-04-05 16:13修改过]

banq
2008-04-07 10:14
可以吧,主要是这个游离对象其实是一个代理对象,但你试图downcast为Customer时就出错。

猜你喜欢