spring事务控制InvalidDataAccessApiUsageException: Write operations are not allowed

2010-08-23 16:31:14,765 ERROR (StandardWrapperValve.java:250) - Servlet.service() for servlet action threw exception
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition
	at org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1071)
	at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:614)
	at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
	at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:612)
	at com.gdcn.bpaf.common.base02.BaseHibernateDAOImpl.save(BaseHibernateDAOImpl.java:62)
	at com.cmmi.task.service.impl.ProtWeyServiceImpl.genProjeeklyReport(ProtWeyServiceImpl.java:133)
	at com.cmmi.task.service.impl.ProtWeyServiceImpl.genProjeekly(ProtWeyServiceImpl.java:101)
	at com.cmmi.task.service.impl.ProtWeyServiceImpl.genProjeekly(ProtWeyServiceImpl.java:60)



又发现这个问题了,简单归纳一下就是在对数据库进行写操作的时候,被spring的事务机制控制了。然后检查一下spring的事务配置里面有没有对exception方法中提示的gen***开头的配置属性。
以下是我的配置:
<property name="transactionAttributes">
            <props>
                <prop key="save*">PROPAGATION_REQUIRED</prop>
                <prop key="create*">PROPAGATION_REQUIRED</prop>
                <prop key="del*">PROPAGATION_REQUIRED</prop>
                 <prop key="mod*">PROPAGATION_REQUIRED</prop>
                 <prop key="update*">PROPAGATION_REQUIRED</prop>
                 <prop key="remove*">PROPAGATION_REQUIRED</prop>
                 <prop key="insert*">PROPAGATION_REQUIRED</prop>
                 <prop key="read*">PROPAGATION_REQUIRED</prop>
                 <prop key="add*">PROPAGATION_REQUIRED</prop>
                <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
            </props>
        </property>

明显少了gen*的配置,加上或者将方法名改掉即可

你可能感兴趣的:(java,DAO,spring,orm,servlet)