hibernate整合spring异常处理

来源:互联网 发布:mac如何解密外置硬盘 编辑:程序博客网 时间:2024/06/08 01:20

在spring整合hibernate是初学者会遇到这样一个问题:

org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

这是这是因为没有配置事务管理器:

在beans.xml文件,即spring 配置文件中对事务管理器进行配置如下:

<!--1.配置事务管理器--><bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">    <property name="sessionFactory" ref="sessionFactory"/></bean><!--2.开启事务注解--><tx:annotation-driven transaction-manager="hibernateTransactionManager"/>

同时在Action调用的service层类名上加上注解:@Transactional 



原创粉丝点击