Open lexburner opened 7 years ago
动态生成的类无法在远程序列化,可以在server端转换成实际的model类(com.example.moton.annotation.api.RemoteStudent)在返回,或者对需要远程传输的对象进行单独封装吧
@rayzhang0603 嗯,消费方访问懒加载属性这个想法已经放弃了,打算深拷贝之后再return给消费端。现在还有一个问题,服务方自己getOne()一个对象(getOne是获得一个对象,但是这个对象是懒加载的),服务端自己访问这个对象也会报错,提示session已经关闭了。
org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:148) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:266) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:68) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at com.example.moton.annotation.api.RemoteStudent_$$_jvstd39_0.getName(RemoteStudent_$$_jvstd39_0.java) ~[na:na] at com.example.moton.annotation.server.RemoteStudentApiImp.getOne(RemoteStudentApiImp.java:38) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_79] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_79] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_79] at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_79] at com.weibo.api.motan.rpc.DefaultProvider.invoke(DefaultProvider.java:57) ~[motan-core-0.2.1.jar:na] at com.weibo.api.motan.rpc.AbstractProvider.call(AbstractProvider.java:47) ~[motan-core-0.2.1.jar:na] at com.weibo.api.motan.transport.ProviderMessageRouter.call(ProviderMessageRouter.java:96) ~[motan-core-0.2.1.jar:na] at com.weibo.api.motan.transport.ProviderProtectedMessageRouter.call(ProviderProtectedMessageRouter.java:82) ~[motan-core-0.2.1.jar:na] at com.weibo.api.motan.transport.ProviderMessageRouter.handle(ProviderMessageRouter.java:91) ~[motan-core-0.2.1.jar:na] at com.weibo.api.motan.transport.support.DefaultRpcHeartbeatFactory$HeartMessageHandleWrapper.handle(DefaultRpcHeartbeatFactory.java:82) ~[motan-core-0.2.1.jar:na] at com.weibo.api.motan.transport.netty.NettyChannelHandler.processRequest(NettyChannelHandler.java:139) ~[motan-transport-netty-0.2.1.jar:na] at com.weibo.api.motan.transport.netty.NettyChannelHandler.access$000(NettyChannelHandler.java:47) ~[motan-transport-netty-0.2.1.jar:na] at com.weibo.api.motan.transport.netty.NettyChannelHandler$1.run(NettyChannelHandler.java:116) ~[motan-transport-netty-0.2.1.jar:na] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_79] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_79] at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]
现在思路是配置一个过滤器,用来在服务端打开事务管理器的session绑定到当前线程。想听听你们的想法。(实际开发中使用的motan,这个问题应该还是挺常见的,懒加载不可避免)
这个可能也没有什么好的办法,即使不是rpc请求也同样存在这个问题。hibernate延迟加载只有在session有效时才能使用,如果必须使用lazy的话,可以在服务中每次请求开启一个session。
`com.weibo.api.motan.exception.MotanFrameworkException: error_message: decode response error: class not found, status: 503, error_code: 20003,r=null at com.weibo.api.motan.protocol.rpc.DefaultRpcCodec.decode(DefaultRpcCodec.java:130) ~[motan-core-0.2.1.jar:na] at com.weibo.api.motan.transport.netty.NettyDecoder.decode(NettyDecoder.java:105) ~[motan-transport-netty-0.2.1.jar:na] at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:282) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:274) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:261) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44) ~[netty-3.2.5.Final.jar:na] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_79] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_79] at java.lang.Thread.run(Thread.java:745) ~[na:1.7.079] Caused by: java.lang.ClassNotFoundException: com.example.moton.annotation.api.RemoteStudent$$_jvst4fb_0 at java.net.URLClassLoader$1.run(URLClassLoader.java:366) ~[na:1.7.0_79] at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[na:1.7.0_79] at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_79] at java.net.URLClassLoader.findClass(URLClassLoader.java:354) ~[na:1.7.0_79] at java.lang.ClassLoader.loadClass(ClassLoader.java:425) ~[na:1.7.0_79] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.7.0_79] at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ~[na:1.7.0_79] at java.lang.Class.forName0(Native Method) ~[na:1.7.0_79] at java.lang.Class.forName(Class.java:274) ~[na:1.7.0_79] at com.weibo.api.motan.util.ReflectUtil.forNameWithoutCache(ReflectUtil.java:142) ~[motan-core-0.2.1.jar:na] at com.weibo.api.motan.util.ReflectUtil.forName(ReflectUtil.java:130) ~[motan-core-0.2.1.jar:na] at com.weibo.api.motan.protocol.rpc.DefaultRpcCodec.decodeResponse(DefaultRpcCodec.java:371) ~[motan-core-0.2.1.jar:na] at com.weibo.api.motan.protocol.rpc.DefaultRpcCodec.decode(DefaultRpcCodec.java:125) ~[motan-core-0.2.1.jar:na] ... 16 common frames omitted
2016-12-13 00:46:23.836 ERROR 19580 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.weibo.api.motan.exception.MotanFrameworkException: error_message: decode response error: class not found, status: 503, error_code: 20003,r=null] with root cause
java.lang.ClassNotFoundException: com.example.moton.annotation.api.RemoteStudent_$$_jvst4fb_0 at java.net.URLClassLoader$1.run(URLClassLoader.java:366) ~[na:1.7.0_79] at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[na:1.7.0_79] at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_79] at java.net.URLClassLoader.findClass(URLClassLoader.java:354) ~[na:1.7.0_79] at java.lang.ClassLoader.loadClass(ClassLoader.java:425) ~[na:1.7.0_79] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.7.0_79] at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ~[na:1.7.0_79] at java.lang.Class.forName0(Native Method) ~[na:1.7.0_79] at java.lang.Class.forName(Class.java:274) ~[na:1.7.0_79] at com.weibo.api.motan.util.ReflectUtil.forNameWithoutCache(ReflectUtil.java:142) ~[motan-core-0.2.1.jar:na] at com.weibo.api.motan.util.ReflectUtil.forName(ReflectUtil.java:130) ~[motan-core-0.2.1.jar:na] at com.weibo.api.motan.protocol.rpc.DefaultRpcCodec.decodeResponse(DefaultRpcCodec.java:371) ~[motan-core-0.2.1.jar:na] at com.weibo.api.motan.protocol.rpc.DefaultRpcCodec.decode(DefaultRpcCodec.java:125) ~[motan-core-0.2.1.jar:na] at com.weibo.api.motan.transport.netty.NettyDecoder.decode(NettyDecoder.java:105) ~[motan-transport-netty-0.2.1.jar:na] at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:282) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:274) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:261) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44) ~[netty-3.2.5.Final.jar:na] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_79] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_79] at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]`
远程调用返回一个对象,在消费方访问懒加载属性时报错。我也知道是基于动态字节码技术来实现的懒加载,但是项目中实际使用懒加载属性不可避免。想请教一下motan团队能不能提供什么思路,可以让消费方能够访问实体类的懒加载属性?