今天遇到一个奇怪的问题,使用Hibernate执行查询语句的时候,数据中的数据无缘地被改变了。首先想到的是把持久态的对象在Action中改变了属性值,但是没发现有这样的操作。百思不得其解。使用Debug模式跟踪了一下,发现确实是在list方法执行时出现对数据的莫名更改,而我用JUnit进行单元测试时,却没有这样的情况。
public List<T> findByHql(String hql, int startPos, int length,Object[] paramValues) {
session = getCurrentSession();
Query query = session.createQuery(hql);
if (paramValues!=null&¶mValues.length>0){
for (int i = 0; i < paramValues.length; i++) {
query.setParameter(i, paramValues[i]);
}
}
query.setFirstResult(startPos);
query.setMaxResults(length);
List<T> list = query.list();
return list;
}
解决办法,在Spring中的事务控制部分将该方法配置成只读方式:
<tx:attributes>
<tx:method name="add*" propagation="REQUIRES_NEW" />
<tx:method name="update*" propagation="REQUIRES_NEW" />
<tx:method name="delete*" propagation="REQUIRES_NEW" />
<tx:method name="find*" read-only="true" />
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
分享到:
相关推荐
1209 – The MySQL server is running with the–read-only option so it cannot execute this statement 一般这个错误有两种原因: 1.连到从库了。从库一般设置为只读。 2.主库的read_only参数被修改为1 开发人员是...
Spring Boot Documentation 1. About the Documentation 2. Getting Help 3. First Steps 4. Working with Spring Boot 5. Learning about Spring Boot Features 6. Moving to Production 7. Advanced Topics II. ...
*" read-only="true"/> eclipse出不来自动补齐功能。 要在开头加上这二句: 1.xmlns:tx="http://www.springframework.org/schema/tx" 2....
使用Spring提供的Open Session In View而引起Write operations are not allowed in read-only mode (FlushMode.NEVER) 错误解决
每个角色都有一个操作:USER = VIEW ONLY,ADMIN = READ / WRITE,SUPER = CREATE。 所有密码均使用DES加密,并使用argon2编码,以确保密码强度高。科技栈Java专家弹簧靴百里香叶引导程序jQuery的sockjsDocker堆栈...
We're certainly pleased that you have acquired the only published book fully devoted to Spring Security 4.2. Before we get started with the book, we would like to give you an overview of how the book...
*" read-only="true"/> </tx:advice> <!-- 那些类的哪些方法参与事务 --> (* com.ccc..*.*(..))"/> <aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/> <!-- 配置...
<?xml version="1.0" encoding="UTF-8... *" read-only="true"/> *" propagation="REQUIRED"/> *" propagation="REQUIRED"/> *" propagation="REQUIRED"/> *" propagation="REQUIRED"/> </beans>
*" read-only="true" /> *" /> *" propagation="NEVER" /> --> destroy-method="close"> ${jdbc.driverClassName}" /> ${jdbc.url}" /> ${jdbc.username}" /> ${jdbc....
每个角色都有一个操作:USER = VIEW ONLY,ADMIN = READ / WRITE,SUPER = CREATE。 所有密码均使用AES加密,并使用scrypt编码,以确保密码强度高。 科技栈 Kotlin 专家 弹簧靴 百里香叶 引导程序 jQuery的 sockjs ...
无需写hibernate的配置文件,而是将hibernate的配置直接加入到spring配置文件中 配置hibernate的映射文件地址 --> <value>com/direct/domain/Employee.hbm.xml</value> <value>...
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=... *" propagation="REQUIRED" read-only="true" /> ...
<?xml version="1.0" encoding="UTF-8"?... *" read-only="true"/> <!-- 那些类的哪些方法参与事务 --> (* com.longxian.drp.manager.*.*(..))" advice-ref="txAdvice"/> </aop:config> </beans>
*" read-only="true" /> *" propagation="REQUIRED" /> *" propagation="REQUIRED" /> *" propagation="REQUIRED" /> *" propagation="REQUIRED" /> <!-- 这个映射配置主要是用来进行静态...
<!--配置连接池--> ... *" read-only="true"/> *" propagation="REQUIRED"/> <!--配置切面--> (* com.itheima.service.impl.*.*(..))"/> <aop:advisor advice-ref="advice" pointcut-ref=
import javax.persistence.Column... *" read-only="true" /> *" propagation="REQUIRED" /> *" propagation="REQUIRED" /> *" propagation="REQUIRED" /> *" propagation="REQUIRED" /> </beans>
Spring+iBatis+JOTM实现JTA事务: 如何处理跨库事物:spring + jtom 的jta事务是个很好的选择. 这个源码示例非常不错,包括所有的源码... *" read-only="true" rollback-for="Exception"/> ...... ...... ......
Numerical-Analysis-Hands-on-Experiments上海科技大学 2018-2019 学年第二学期数值分析(GEMA1008)上机实验。... This repository is archived and read-only since all work has been finished.
as the easy-to-digest and fun-to-read Spring boot documentation the Java community has been waiting for since Boot took the community by storm. Craigs accessible writ- ing style and sweeping analysis ...
*" read-only="true"/> </tx:advice> //tx标签代表时间传播 <aop:config>//切入 (* com.cstp.service.*.*(..))"/> <aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice"/> <!-- ...