读取的时候session已经关了,把读取的时候放在session还开着的时候
解决方案 »
- 急:SaaS模式,spring根据登录用户自动修改datesource并重新加载
- 如何手动给hibernate uuid赋值
- javamail的错误 有经验的进
- 表格数据排序问题
- SUN认证
- 急,简单送分题,请快帮忙,Maven新手提问。
- HibernateCallback 问题--请高手花一分钟指点
- 如何用ant 直接发布EAR 到 websphere 6中
- 有了一个有状态的SessionBean,如何使用?
- tomcat分配内存的问题
- org.apache.struts.validator.
- 大家有没有用JasperReport+iReport制作过图形报表?我用iReport画饼状图形的时候编译可以通过,执行出错,报什么Script错
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
2006-06-22 15:53:56,859 [org.hibernate.LazyInitializationException]-[ERROR] failed to lazily initialize a collection
of role: com.jacky.reallb.modal.Productclass.product - no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jacky.reallb.modal.
Productclass.product - no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistent
Collection.java:191)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
at com.jacky.reallb.struts.action.AdminproductclassloadAction.execute(AdminproductclassloadAction.java:70)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
java.util.Iterator it = obj.getProduct().iterator();
之前,关了session?
懒加载是在需要的时候才去数据库获取所需字段的。
obj=this.getProductclassService().getProductclass(new Long(id));
//System.out.println("productclass ="+obj.toString());
/*test one-to-many begin*/
java.util.Iterator it = obj.getProduct().iterator();
while (it.hasNext())
{
Product pVO = (Product) it.next();
System.out.print("product name="+pVO.getName());
System.out.print("product serial="+pVO.getSerial());
}
/*test one-to-many end*/怎样达到我这目的呀?
<key column="ID"/>
<one-to-many class="com.jacky.reallb.modal.Product"/>
</set>改成
<set name="product" table="SSH_PRODUCT" cascade="none" lazy="false" inverse="true" order-by="updt desc">
<key column="ID"/>
<index column="ID" type="integer" />
<one-to-many class="com.jacky.reallb.modal.Product"/>
</set>
Severity Description Resource In Folder Location Creation Time Id
2 The content of element type "set" must match "(meta*,subselect?,cache?,synchronize*,comment?,key,(element|one-to-many|many-to-many|composite-element|many-to-any),loader?,sql-insert?,sql-update?,sql-delete?,sql-delete-all?,filter*)". Productclass.hbm.xml realSSH/WEB-INF/src/com/jacky/reallb/modal line 26 June 24, 2006 2:06:05 PM 5257
自己写方法实现.
但不知为什么我的就不行,而且这样的错在网上找不到相应的办法呀!
<key column="ID"/>
<one-to-many class="com.jacky.reallb.modal.Product"/>
</set>***************************************************************************
<many-to-one
name="productclass"
class="com.jacky.reallb.modal.Productclass"
column="PRODUCTCLASSID"
cascade="none"
not-null="true"
outer-join="auto"
/> 请注意,在one_to_many和many_to_one两面进行配置的时候,“<key column="ID"/>”,这个key要指向many方要映射的字段,并且两面的配置都是一样的;
<set name="product" table="SSH_PRODUCT" cascade="none" lazy="false" inverse="true" order-by="updt desc">
<key column="ID"/>
<one-to-many class="com.jacky.reallb.modal.Product"/>
</set>***************************************************************************
<many-to-one
name="productclass"
class="com.jacky.reallb.modal.Productclass"
column="PRODUCTCLASSID"
cascade="none"
not-null="true"
outer-join="auto"
/>
这样的写法
设表1:table1,表2:table2,有一对多关系,表1的id与表2的table1_id关联;
在jsp页面上:
<nbean:formBean name="table1FormBean" sql="select * from table1 where ......"/>
<logic:notEmpty name="table1FormBean" porperty="_coll">
<bean:define id="tableId" name="table1FormBean" property="id"/>
</logic:notEmpty>
<nbean:formBean name="tableFormBean" sql="select * from table2 where table1_id='${table1Id}'/>
接作可以一对多显示,可以分页,不写一行java代码。参见:newxy(新坐标)范例:http://www.newxy.net/zh_cn/samples/sample1/demo.jsp
换成set = null;
http://community.csdn.net/Expert/topic/4883/4883920.xml?temp=.1669275
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter> <filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<key column="bbsid"/>
<index column="id" type="integer"/>
<one-to-many class="BbsReply"/>
</map>