`
hanfeng450
  • 浏览: 29128 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

用spring事务时hibernate无法抓取对象

阅读更多
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对象.
除此之外还有其他方法吗?
分享到:
评论
1 楼 bingyunxl 2008-03-30  
会话没有传递到视图层,可以通过对象拷贝或者使用spring自己的一个解决方式,之前的帖子中有,可以找找

相关推荐

Global site tag (gtag.js) - Google Analytics