Hibernate中的懒加载异常 ERROR LazyInitializationException:19 - could not initialize proxy - no Session我把<many-to-one>端的lazay已经设为了false,怎么还出现这个异常啊,有会的教下我,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 dao代码: /** * 根据任务ID查询 * @param task_id * @return */ public Task get(int task_id) { return (Task)getHibernateTemplate().load(Task.class, task_id); }测试代码: @Test public void testSel() { Task t = dao.get(1); System.out.println(t.getType()); //根据id来查询Task的相关信息时会有could not initialize proxy - no Session 抛出 }task.hbm.xml <class name="com.om.fee.model.Task" table="task" catalog="om"> <id name="task_id" type="java.lang.Integer"> <column name="task_id" /> <generator class="native"></generator> </id> <property name="reason" type="java.lang.String"> <column name="reason" length="65535" /> </property> <property name="type" type="java.lang.String"> <column name="type" length="30" /> </property> <property name="start_time" type="java.util.Date"> <column name="start_time" length="10" /> </property> <property name="end_time" type="java.util.Date"> <column name="end_time" length="10" /> </property> <set name="fees" inverse="true"> <key> <column name="task_id" not-null="true"/> </key> <one-to-many class="com.om.fee.model.Fee"/> </set> </class>fee.hbm.xml<class name="com.om.fee.model.Fee" table="fee" catalog="om"> <id name="fee_id" type="java.lang.Integer"> <column name="fee_id" /> <generator class="native"></generator> </id> <many-to-one name="task" column="task_id" class="com.om.fee.model.Task" not-null="true" lazy="false"> </many-to-one> <property name="proposer" type="java.lang.String"> <column name="proposer" length="20" /> </property> <property name="department" type="java.lang.String"> <column name="department" /> </property> <property name="reason" type="java.lang.String"> <column name="reason" length="500" /> </property> <property name="money" type="java.lang.Float"> <column name="money" precision="12" scale="0" /> </property> <property name="actual_money" type="java.lang.Long"> <column name="actual_money" precision="12" scale="0" /> </property> <property name="time" type="java.sql.Date"> <column name="time" length="10" /> </property> <property name="approver" type="java.lang.String"> <column name="approver" length="10" /> </property> <property name="note" type="java.lang.String"> <column name="note" length="500" /> </property> </class>task 和 fee是1:N关系 有才的代码 急求视频网站后台管理模板!!! 问一个有关struts1标签的使用 hibernate 映射文件怎么配置降序索引 struts2 中List问题 谁给我个B/S代码啊 有关工作流OSWorkFlow的问题, 请达人帮忙 求教,关于JNI技术 cascade="all"时插入不了记录 简单问题求教关于数据库查询优化的问题 java.io.IOException: Error: Attempt to clear a buffer that's already been flushed这是什么错误啊 Apache和Tomcat集成问题
* 根据任务ID查询
* @param task_id
* @return
*/
public Task get(int task_id)
{
return (Task)getHibernateTemplate().load(Task.class, task_id);
}
测试代码: @Test
public void testSel()
{
Task t = dao.get(1);
System.out.println(t.getType()); //根据id来查询Task的相关信息时会有could not
initialize proxy - no Session 抛出 }
task.hbm.xml <class name="com.om.fee.model.Task" table="task" catalog="om">
<id name="task_id" type="java.lang.Integer">
<column name="task_id" />
<generator class="native"></generator>
</id>
<property name="reason" type="java.lang.String">
<column name="reason" length="65535" />
</property>
<property name="type" type="java.lang.String">
<column name="type" length="30" />
</property>
<property name="start_time" type="java.util.Date">
<column name="start_time" length="10" />
</property>
<property name="end_time" type="java.util.Date">
<column name="end_time" length="10" />
</property>
<set name="fees" inverse="true">
<key>
<column name="task_id" not-null="true"/>
</key>
<one-to-many class="com.om.fee.model.Fee"/>
</set>
</class>
fee.hbm.xml<class name="com.om.fee.model.Fee" table="fee" catalog="om">
<id name="fee_id" type="java.lang.Integer">
<column name="fee_id" />
<generator class="native"></generator>
</id>
<many-to-one name="task" column="task_id" class="com.om.fee.model.Task" not-null="true" lazy="false">
</many-to-one>
<property name="proposer" type="java.lang.String">
<column name="proposer" length="20" />
</property>
<property name="department" type="java.lang.String">
<column name="department" />
</property>
<property name="reason" type="java.lang.String">
<column name="reason" length="500" />
</property>
<property name="money" type="java.lang.Float">
<column name="money" precision="12" scale="0" />
</property>
<property name="actual_money" type="java.lang.Long">
<column name="actual_money" precision="12" scale="0" />
</property>
<property name="time" type="java.sql.Date">
<column name="time" length="10" />
</property>
<property name="approver" type="java.lang.String">
<column name="approver" length="10" />
</property>
<property name="note" type="java.lang.String">
<column name="note" length="500" />
</property>
</class>task 和 fee是1:N关系