(给200分,不够我再加)我用hibernate时,产生错误:Failed to lazily initialize a collection obj.getSetupServiceTickets()是一个set吧Set s =(Set)obj.getSetupServiceTickets(); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 80%的可能是由于当你设置lazy="true"后在session关闭之后读取数据集合 导致的解决方法两个1.laze="false" 这样无法延迟加载了2.在mgr.getRequestSetupTicketById这个method中, session close之前 使用Hibernate.initialize()方法来加载集合数据Hope help 就是,延迟加载的数据在session关闭后就无法使用了 不是session的问题,我是在其关闭前调的get obj.getSetupServiceTickets()是一个set吧Set s =(Set)obj.getSetupServiceTickets();对是set 把你getRequestSetupTicketById的代码帖出来看看 数据库里有RequestSetupTicket对应的表的数据,但没有setupServiceTickets和中间表REQUEST_TICKET_SETUP_TICKET的数据========================================================你自己都说原因拉,数据都没有,怎么能initialize 就算没有数据也不会报 Failed to lazily initialize 这个异常.. 问题已经找到,在many-to-many的另外一段的ServiceTicket.hbm.xml的问题,这是原来的: <joined-subclass name="SetupServiceTicket" table="SETUP_SERVICE_TICKET"> <key column="SERVICE_TICKET_ID"/> <set name="requestSetupTickets" table="REQUEST_TICKET_SETUP_TICKET" inverse="true" lazy="true" cascade="none"> <key column="SERVICE_TICKET_ID"/> <many-to-many column="REQUEST_TICKET_NO" class="RequestSetupTicket" /> </set> <set name="setupDevices" table="SETUP_SERVICE_TICKET_DEVICE" cascade="save-update" inverse="true"> <key column="SETUP_SERVICE_TICKET_ID"/> <one-to-many class="SetupServiceTicketDevice"/> </set> <many-to-one name="saleDept" column="SALE_DEPT_ID" class="Department" not-null="false" cascade="none"/> <property name="setupType" column="SETUP_TYPE" type="string" length="5" not-null="true"/> <property name="expectOutDate" column="EXPECT_OUT_DATE" type="date" not-null="true"/> <property name="sales" column="SALES" type="string" length="20" not-null="false"/> <property name="invoiceHeader" column="INVOICE_HEADER" type="string" length="50" not-null="false"/> <property name="uniqueInvoiceId" column="UNIQUE_INVOICE_ID" type="string" length="10" not-null="false"/> <property name="paymentClause" column="PAYMENT_CLAUSE" type="string" length="5" not-null="true"/> <property name="projectId" column="PROJECT_ID" type="string" length="50" not-null="true"/> <property name="needToGo" column="NEED_TOGO" type="string" length="5" not-null="true"/> </joined-subclass> 这是改过后的: <joined-subclass name="SetupServiceTicket" table="SETUP_SERVICE_TICKET" proxy="SetupServiceTicket"> <key column="SERVICE_TICKET_ID"/> <set name="requestSetupTickets" table="REQUEST_TICKET_SETUP_TICKET" inverse="false" lazy="true" cascade="save-update"> <key column="SERVICE_TICKET_ID"/> <many-to-many column="REQUEST_TICKET_NO" class="RequestSetupTicket" /> </set> <set name="setupDevices" table="SETUP_SERVICE_TICKET_DEVICE" lazy="true" cascade="save-update" inverse="true"> <key column="SETUP_SERVICE_TICKET_ID"/> <one-to-many class="SetupServiceTicketDevice"/> </set> <many-to-one name="saleDept" column="SALE_DEPT_ID" class="Department" not-null="false" cascade="none"/> <property name="setupType" column="SETUP_TYPE" type="string" length="5" not-null="true"/> <property name="expectOutDate" column="EXPECT_OUT_DATE" type="date" not-null="true"/> <property name="sales" column="SALES" type="string" length="20" not-null="false"/> <property name="invoiceHeader" column="INVOICE_HEADER" type="string" length="50" not-null="false"/> <property name="uniqueInvoiceId" column="UNIQUE_INVOICE_ID" type="string" length="10" not-null="false"/> <property name="paymentClause" column="PAYMENT_CLAUSE" type="string" length="5" not-null="true"/> <property name="projectId" column="PROJECT_ID" type="string" length="50" not-null="true"/> <property name="needToGo" column="NEED_TOGO" type="string" length="5" not-null="true"/> </joined-subclass> 如果有人能给出以上答案的精准的解释,或者给小弟推荐几个好用的hibernator生成工具和wssd里hibernate的插件(包括使用说明),我会把分奖励给他(她)。但鉴于以上诸位的答案并不靠谱,所以本贴只能给出100分,请诸位谅解。我还有一贴http://community.csdn.net/Expert/topic/3608/3608328.xml?temp=.2402002很简单,怎没人去拿分 不是session的问题,我是在其关闭前调的get===========================================你在关闭之前就算是调用get方法...也不会加载的...除非你getXXX().size()或者其他的方法访问集合后才可以加载...至于楼主怎么改的我不知道...但是这个异常究竟在什么时候报出..楼主可以查查源码 菜鸟求教,java工厂模式为什么要实现接口 如何在Action获得url参数 在线等 急 struts2 上传组件问题 struts2 中‘%{}’的意思? jasperreport在linux下报错? 想在eclispe下连接tomcat,出现问题,请高手回答,马上给分 菜鸟请教:工厂是什么? WEBLOGIC下的WEB应用文件的放置问题 oracle9i是否支持ejb? 某公司笔式题,欢迎参加有分讨论! 使用weblogic开发的朋友,请进来一下,如何获得绝对路径下的文件??? 如何替换JVM中的ClassLoader
1.laze="false" 这样无法延迟加载了
2.在mgr.getRequestSetupTicketById这个method中, session close之前 使用Hibernate.initialize()方法来加载集合数据Hope help
========================================================
你自己都说原因拉,数据都没有,怎么能initialize
Failed to lazily initialize 这个异常..
这是原来的:
<joined-subclass name="SetupServiceTicket" table="SETUP_SERVICE_TICKET">
<key column="SERVICE_TICKET_ID"/>
<set name="requestSetupTickets" table="REQUEST_TICKET_SETUP_TICKET" inverse="true" lazy="true" cascade="none">
<key column="SERVICE_TICKET_ID"/>
<many-to-many column="REQUEST_TICKET_NO" class="RequestSetupTicket" />
</set> <set name="setupDevices" table="SETUP_SERVICE_TICKET_DEVICE" cascade="save-update" inverse="true">
<key column="SETUP_SERVICE_TICKET_ID"/>
<one-to-many class="SetupServiceTicketDevice"/>
</set>
<many-to-one name="saleDept" column="SALE_DEPT_ID" class="Department" not-null="false" cascade="none"/>
<property name="setupType" column="SETUP_TYPE" type="string" length="5" not-null="true"/>
<property name="expectOutDate" column="EXPECT_OUT_DATE" type="date" not-null="true"/> <property name="sales" column="SALES" type="string" length="20" not-null="false"/>
<property name="invoiceHeader" column="INVOICE_HEADER" type="string" length="50" not-null="false"/>
<property name="uniqueInvoiceId" column="UNIQUE_INVOICE_ID" type="string" length="10" not-null="false"/>
<property name="paymentClause" column="PAYMENT_CLAUSE" type="string" length="5" not-null="true"/>
<property name="projectId" column="PROJECT_ID" type="string" length="50" not-null="true"/>
<property name="needToGo" column="NEED_TOGO" type="string" length="5" not-null="true"/>
</joined-subclass>
<key column="SERVICE_TICKET_ID"/>
<set name="requestSetupTickets" table="REQUEST_TICKET_SETUP_TICKET" inverse="false" lazy="true" cascade="save-update">
<key column="SERVICE_TICKET_ID"/>
<many-to-many column="REQUEST_TICKET_NO" class="RequestSetupTicket" />
</set> <set name="setupDevices" table="SETUP_SERVICE_TICKET_DEVICE" lazy="true" cascade="save-update" inverse="true">
<key column="SETUP_SERVICE_TICKET_ID"/>
<one-to-many class="SetupServiceTicketDevice"/>
</set>
<many-to-one name="saleDept" column="SALE_DEPT_ID" class="Department" not-null="false" cascade="none"/>
<property name="setupType" column="SETUP_TYPE" type="string" length="5" not-null="true"/>
<property name="expectOutDate" column="EXPECT_OUT_DATE" type="date" not-null="true"/> <property name="sales" column="SALES" type="string" length="20" not-null="false"/>
<property name="invoiceHeader" column="INVOICE_HEADER" type="string" length="50" not-null="false"/>
<property name="uniqueInvoiceId" column="UNIQUE_INVOICE_ID" type="string" length="10" not-null="false"/>
<property name="paymentClause" column="PAYMENT_CLAUSE" type="string" length="5" not-null="true"/>
<property name="projectId" column="PROJECT_ID" type="string" length="50" not-null="true"/>
<property name="needToGo" column="NEED_TOGO" type="string" length="5" not-null="true"/>
</joined-subclass>
我还有一贴
http://community.csdn.net/Expert/topic/3608/3608328.xml?temp=.2402002
很简单,怎没人去拿分