没有写权限

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

出现这种异常,我的解决方法是:

在ApplicationContext.xml中配置
<!--配置事务拦截器-->
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
第一个bean的prop是dao中的方法名首单词,如:
public void addLinkMan() {...}中的add。

<!-- 配置事物自动代理 -->
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>linkManDAOImpl</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>

第二个bean中第一个property中的value定义Spring中bean的id,如
<bean id="linkManDAOImpl" class="com.shortmassage.dao.LinkManDAOImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
中的id="linkManDAOImpl"。
第二个property中value定义定义第一个bean的id,关联起来。

你可能感兴趣的:(DAO,spring,bean,xml)