---
title: "用spring事务时hibernate无法抓取对象"
author: "hanfeng450"
date: "2008-03-30T15:21:51Z"
tags: []
slug: "spring-hibernate"
draft: false
lastmod: "2008-03-30T15:21:51Z"
id: 177783
url: "https://windmoon.iteye.com/blog/177783"
---

spring 的配置文件
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	
	
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="find*" read-only="true"
				rollback-for="my.duds.exception.DudsException" />
			<tx:method name="delete*" read-only="false"
				rollback-for="my.duds.exception.DudsException" />
			<tx:method name="update*" read-only="false"
				rollback-for="my.duds.exception.DudsException" />
			<tx:method name="save*" read-only="false" 
				rollback-for="my.duds.exception.DudsException"/>
		</tx:attributes>
	</tx:advice>
	
	<aop:config proxy-target-class="true">
		<aop:advisor
			pointcut="execution(* my.duds.services.impl..*.*(..))"
			advice-ref="txAdvice" />
	</aop:config>
	
	
	<!-- 注入SessionFactory -->
	<bean id="daoImpl"
		class="my.duds.dao.impl.DaoImpl">
		<property name="sessionFactory">
			<ref bean="sessionFactory"></ref>
		</property>
	</bean>
hibernate的配置文件 News.hbm.xml
<hibernate-mapping>
    <class name="my.duds.vo.News" table="News" schema="dbo" catalog="Duds">
        <id name="newsId" type="java.lang.Long">
            <column name="newsID" precision="18" scale="0" />
            <generator class="native" />
        </id>
        <many-to-one name="admin" class="my.duds.vo.Admin" fetch="select">
            <column name="adminID" precision="18" scale="0" />
        </many-to-one>
        <many-to-one name="newsType" class="my.duds.vo.NewsType" fetch="select">
            <column name="newsTypeID" precision="18" scale="0" />
        </many-to-one>
        <property name="newsTitle" type="java.lang.String">
            <column name="newsTitle" length="1000" />
        </property>
        <property name="newsText" type="java.lang.String">
            <column name="newsText" />
        </property>
        <property name="newsPublishDate" type="java.util.Date">
            <column name="newsPublishDate" length="23" />
        </property>
        <property name="newsClickCount" type="java.lang.Integer">
            <column name="newsClickCount" not-null="true" />
        </property>
    </class>
</hibernate-mapping>

当我在jsp页面用 news.newType.newTypeName时,就会抛出session已经关闭的异常,
继而无法获取到newTypeName.
请教一下高手这个是什么问题.有什么办法解决.
我目前只有用left join fetch newType 才能得到newType对象.
除此之外还有其他方法吗?