<pre class="brush:java; toolbar: true; auto-links: false;"></pre>
<pre class="brush:java; toolbar: true; auto-links: false;"> public String saveRole(Integer app_id) throws Exception {
//先插入,比如插入了10条
save();
//再查询,这时查不到刚才插入的10条
getUserRole();
}
/**
* 保存新增或修改的对象.
*/
public void save(final T entity){
try {
Session session = getSession();
session.saveOrUpdate(entity);
} catch (Exception e) {
e.printStackTrace();
}
}
</pre>
<pre class="brush:xml; toolbar: true; auto-links: false;"> <tx:advice id="txAdviceBase" transaction-manager="transactionManagerBase">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"
rollback-for="Throwable" />
<tx:method name="update*" propagation="REQUIRED"
rollback-for="Throwable" />
<tx:method name="create*" propagation="REQUIRED"
rollback-for="Throwable" />
<tx:method name="delete*" propagation="REQUIRED"
rollback-for="Throwable" />
<tx:method name="run*" propagation="REQUIRED" rollback-for="Throwable" />
<tx:method name="batch*" propagation="REQUIRED"
rollback-for="Throwable" />
<tx:method name="excute*" propagation="REQUIRED"
rollback-for="Throwable" />
<tx:method name="query*" propagation="REQUIRED"
rollback-for="Throwable" />
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com..*.service.*.*(..))"
advice-ref="txAdviceBase" order="1" />
</aop:config>
</pre>
<br>
<br>
<br>
<br>
<br>
<pre class="brush:java; toolbar: true; auto-links: false;"><span style="color:#333333;font-family:Helvetica, Tahoma, Arial, sans-serif;font-size:14px;line-height:24px;background-color:#F5F5F5;">只有saveRole整个方法运行完才能再数据库查到数据。</span> <span style="color:#333333;font-family:Helvetica, Tahoma, Arial, sans-serif;font-size:14px;line-height:24px;background-color:#F5F5F5;">我知道运行saveUserRole()的时候不会插入到数据库,但是应该是存在缓存里的,执行getUserRole()是从缓存里取,为什么查不到啊?</span></pre>
<!-- 注册事务管理器 -->
<bean id="trxMgr" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 注册拦截 -->
<bean id="trxInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<!-- 指定事务管理器 -->
<property name="transactionManager" ref="trxMgr"></property>
<!-- 指定事务策略 -->
<property name="transactionAttributes">
<props><!-- key表示方法,value表示策略 -->
<prop key="save*">PROPAGATION_REQUIRED,ISOLATION_DEFAULT,-Throwable</prop>
<prop key="update*">PROPAGATION_REQUIRED,ISOLATION_DEFAULT,-Throwable</prop>
<prop key="del*">PROPAGATION_REQUIRED,ISOLATION_DEFAULT,-Throwable</prop>
<prop key="*">readOnly</prop>
</props>
</property>
</bean>
<!-- 注册代理 -->
<bean id="trxAutoProxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<!-- 指定哪些需要代理 -->
<property name="beanNames">
<list>
<value>*Dao</value>
<value>*Service</value>
</list>
</property>
<!-- 指定拦截 -->
<property name="interceptorNames">
<list>
<value>trxInterceptor</value>
</list>
</property>
</bean>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。