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();
}
} <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>只有saveRole整个方法运行完才能再数据库查到数据。
我知道运行saveUserRole()的时候不会插入到数据库,但是应该是存在缓存里的,执行getUserRole()是从缓存里取,为什么查不到啊?

解决方案 »

  1.   

        public String saveRole(Integer app_id) throws Exception { 
                //先插入,比如插入了10条 
                save(); 
              conn.commitTrans(); //提交
              //再查询,这时查不到刚才插入的10条 
                getUserRole(); 
        } 
    中间提交一下事务就可以
    为什么要再去查一次呢,你前面保存的时候不是有数据吗,直接拿过来用不就得了,你以为查一次数据库性能不会差一点吗