When integrating hibernate in spring, beginners will encounter such a problem:
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.
This is because there is no transaction manager configured:
In the beans.xml file, that is, the spring configuration file, configure the transaction manager as follows:
<!--1.配置事务管理器--> <bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <!--2.开启事务注解--> <tx:annotation-driven transaction-manager="hibernateTransactionManager"/>
At the same time, add an annotation to the class name of the service layer called by Action: @Transactional