hibernate问题持续更新

问题一:

hibernate中一些不需要维持到数据库中的字段,使用@Transient来维持

问题二:

org.springframework.dao.InvalidDataAccessApiUsageException:Writeoperationsarenotallowedinread-onlymode(FlushMode.NEVER/MANUAL):TurnyourSessionintoFlushMode.COMMIT/AUTOorremove'readOnly'markerfromtransactiondefinition.

atorg.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1186)

atorg.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:696)

atorg.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)

atorg.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)

atorg.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:694)

atcom.bstek.scm.dao.daoImpl.VoucherDaoImpl.addVoucher(VoucherDaoImpl.java:31)

atcom.bstek.scm.bo.fin.impl.VoucherManagerImpl.createVoucher(VoucherManagerImpl.java:48)

解决:

因为事务是在manager层,然后方法createVoucher.create不在配置的事务中.

事务配置

<aop:config>

<!--切入点-->

<aop:advisorpointcut="execution(*com.bstek.scm.bo..*.*(..))"advice-ref="txAdvice"/>

</aop:config>

<!--创建一个切面-->

<tx:adviceid="txAdvice"transaction-manager="TtransactionManager">

<tx:attributes>

<!--只要方法名-->

<tx:methodname="add*"propagation="REQUIRED"

isolation="DEFAULT"rollback-for="com.bstek.scm.common.exception.ManagerException,Exception"/>

<tx:methodname="delete*"propagation="REQUIRED"

isolation="DEFAULT"rollback-for="com.bstek.scm.common.exception.ManagerException,Exception"/>

<tx:methodname="update*"propagation="REQUIRED"

isolation="DEFAULT"rollback-for="com.bstek.scm.common.exception.ManagerException,Exception"/>

<tx:methodname="save*"propagation="REQUIRED"

isolation="DEFAULT"rollback-for="com.bstek.scm.common.exception.ManagerException,Exception"/>

<tx:methodname="insert*"propagation="REQUIRED"

isolation="DEFAULT"rollback-for="com.bstek.scm.common.exception.ManagerException,Exception"/>

<tx:methodname="*"propagation="SUPPORTS"read-only="true"

isolation="DEFAULT"/>

</tx:attributes>

</tx:advice>

所以createVoucher这个方法被认为是只读事务.

将createVoucher改为addVoucher就ok了.

相关推荐