当前位置: 代码迷 >> Java Web开发 >> ,关于RMI远程调用hibernate服务出现有关问题
  详细解决方案

,关于RMI远程调用hibernate服务出现有关问题

热度:4553   发布时间:2016-04-10 23:02:57.0
求助,关于RMI远程调用hibernate服务出现问题
大概是一个RMI远程调用Hinerbate 出现session 无法链接的问题。
有Role  Function两个类,单向多对多关联。中间表permission
Role类
public class BaseGrouptbl implements java.io.Serializable {

private String groupid;
。。。
private Set functions = new HashSet();

下面是Role 的配置文件
<hibernate-mapping>
    <class name="model.BaseGrouptbl" table="BASE_GROUPTBL">
        <id name="groupid" type="string">
            <column name="GROUPID" length="10" />
            <generator class="assigned" />
        </id>
         <set name="functions" table="base_permissiontbl" lazy="false" fetch="join" cascade="save-update">
         <key column="groupid"></key>
         <many-to-many class="model.BaseFunctiontbl" column="funcid"></many-to-many>
        </set>
    </class>
</hibernate-mapping>


然后问题是这样:
当我通过客户端调用 服务端的查询 类Role的方法(方法采用HQL语句查询)时,会出现那种像延时加载而session已关闭时的异常。
可是我确实把lazy设为false了啊。

已确定的:
1、RMI配置无问题,其他方法都可以调用
2、看一下当作服务端的项目的日志,Role 的Function Set 确实有取出来
3、对于Role对象,采用SQL语句查询无问题,可是我还要Function类啊
4、增加没问题,中间表也能加进去
5、当不用远程调用时,方法没问题

最后附上异常:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:368)
at org.hibernate.collection.PersistentSet.add(PersistentSet.java:212)
at com.caucho.hessian.io.CollectionDeserializer.readList(CollectionDeserializer.java:78)
at com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:1703)
at com.caucho.hessian.io.JavaDeserializer$ObjectFieldDeserializer.deserialize(JavaDeserializer.java:387)
at com.caucho.hessian.io.JavaDeserializer.readObject(JavaDeserializer.java:233)
at com.caucho.hessian.io.JavaDeserializer.readObject(JavaDeserializer.java:157)
at com.caucho.hessian.io.SerializerFactory.readObject(SerializerFactory.java:376)
at com.caucho.hessian.io.Hessian2Input.readObjectInstance(Hessian2Input.java:2054)
at com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:1980)
at com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:1972)
at com.caucho.hessian.io.CollectionDeserializer.readList(CollectionDeserializer.java:78)
at com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:1703)
at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:220)
at $Proxy8.queryGroupCommonByhql(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:597)
at org.springframework.remoting.caucho.HessianClientInterceptor.invoke(HessianClientInterceptor.java:219)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy9.queryGroupCommonByhql(Unknown Source)
at test.BaseGrouptblServiceImplTest.testqueryGroupCommonBysql(BaseGrouptblServiceImplTest.java:60)
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:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
  相关解决方案