我现在操作的是中间表对象
po:
public class Role_Plate extends BaseModel {private Plate plate;private UserMag_b_RightTeam role;配置hbm.xml:
 <class name="com.Blank.model.Role_Plate" table="role_plate">
    <id name="id" type="java.lang.String">
            <column name="id" length="50" />
            <generator class="uuid.hex" />
    </id>
     <many-to-one name="plate" class="com.Blank.model.Plate" fetch="select" >
            <column name="plate_id" not-null="true" />
     </many-to-one>
     <many-to-one name="role" class="com.Blank.model.UserMag_b_RightTeam" fetch="select" >
          <column name="role_id" not-null="true" />
     </many-to-one>
而且我也都设置延迟加载了,在一的一方设置lazy="true"
plate:
<set name="rolepowers" inverse="true"  lazy="true">
            <key>
                <column name="id" not-null="true" />
            </key>
            <one-to-many class="com.Blank.model.Role_Plate"  />
        </set>
role:
<set name="rolepowers" inverse="true" lazy="true">
            <key>
                <column name="role_id" not-null="true" />
            </key>
            <one-to-many class="com.Blank.model.Role_Plate" />
        </set>问题是现在我在用户action中想提取
result= this.userRoleService.getRoleFun(roleid);//返回功能与角色集合
现在这个result里面存了2个对像,一个是plate,role但是看他们对象里面的属性值都是空的,而且
ERROR - Servlet.service() for servlet jsp threw exception
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
怎么解决啊!!!

解决方案 »

  1.   

    ERROR - could not initialize proxy - the owning Session was closed
    org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
    还有这个异常!
      

  2.   

    你取消了lazy=true,看看出什么问题。
      

  3.   

    ERROR - could not initialize proxy - the owning Session was closed 
    org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed 
    还有这个异常!是因为你使用了延迟加载,你查询时关闭了session引起的问题,要么你把lazy="false"> 不用延迟 
    或者可以用连接池管理session连接,就可以 不用关掉session
      

  4.   

    默认lazy=true
    你应该改为lazy=false吧
    延时加载关闭
      

  5.   

    session关闭后,访问延迟加载的属性就有问题了
    一般在service层将页面上需要显示的数据准备好,如果是延迟加载的,就先在service中取出来或者用opsessioninvew模式在filter里处理session和事务
      

  6.   

    加不加lazy都还是包这个错误,相同的
      

  7.   

    使用延时加载就不能 查询完后马上关 session 
    你写个过滤器来 关闭session ,在每次请求的时候关上次的session,然后从新打开一个Session 就搞定了
      

  8.   

    具体说下把,最好有贴吗,我在底层直接就是继承HibernateDaoSupport,直接提取出getHibernateTemplate()方法
      

  9.   

    方法一:在service里直接把这个集合的属性先取一遍,这个应该会吧
    方法二:看你用了spring,那就直接在web.xml配置一个filter。
    <filter>
        <filter-name>OpenSessionInViewFilter</filter-name>
        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>OpenSessionInViewFilter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
      

  10.   

    你的result是什么类型的?怎么会有2个对象, 你只要取得List<Role_Plate>, 然后通过Role_Plate.plate和Role_Plate.role获取, 把你的HQL和具体代码发出来看看
      

  11.   

    可定是你在session关闭后使用了延迟加载的对象,要么你吧lazy设置为false  , 要么用到Hibernate.initialize(object)初始化延迟加载对象
      

  12.   

    /**
     * 查询中间表,操作
     */

    public List getRoleFun(String roleid) {
    String sql = "from Role_Plate where role_id = '"+roleid+"' ";
    return this.getHibernateTemplate().find(sql);
    }
     
    }
      

  13.   

    楼主可以看看hibernate对象的三种状态解释,以及openSessionInViewFilter,或许可以解决你的问题
      

  14.   

    感觉 楼上几位 解决办法不是怎么正统,甚至是有些不正确调用延迟加载的对象时 如果原session已经关闭了应该再开一个session比如 role需  session.update(rp.getRole());
    再 rp.getRole() 就可以得到对象了.
      

  15.   

    问题解决,原因还是在lazy上,谢谢大家!!!