`

Spring中的read-only

阅读更多
    今天遇到一个奇怪的问题,使用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&&paramValues.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>
分享到:
评论

相关推荐

    The MySQL server is running with the –read-only option so it cannot execute this statement

    1209 – The MySQL server is running with the–read-only option so it cannot execute this statement 一般这个错误有两种原因: 1.连到从库了。从库一般设置为只读。 2.主库的read_only参数被修改为1 开发人员是...

    spring-boot-reference.pdf

    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. ...

    Spring2.5和Hibernate3集成--学习spring aop ioc

    *" read-only="true"/&gt; eclipse出不来自动补齐功能。 要在开头加上这二句: 1.xmlns:tx="http://www.springframework.org/schema/tx" 2....

    使用Spring引起的错误

    使用Spring提供的Open Session In View而引起Write operations are not allowed in read-only mode (FlushMode.NEVER) 错误解决

    java-web-maven-spring-thyme-secure-des-encrypt-argon2-encoded

    每个角色都有一个操作:USER = VIEW ONLY,ADMIN = READ / WRITE,SUPER = CREATE。 所有密码均使用DES加密,并使用argon2编码,以确保密码强度高。科技栈Java专家弹簧靴百里香叶引导程序jQuery的sockjsDocker堆栈...

    Spring Security, 3rd Edition-Packt Publishing(2017).epub

    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...

    spring applicationContext 配置文件

    *" read-only="true"/&gt; &lt;/tx:advice&gt; &lt;!-- 那些类的哪些方法参与事务 --&gt; (* com.ccc..*.*(..))"/&gt; &lt;aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/&gt; &lt;!-- 配置...

    springmvc-ibatis

    &lt;?xml version="1.0" encoding="UTF-8... *" read-only="true"/&gt; *" propagation="REQUIRED"/&gt; *" propagation="REQUIRED"/&gt; *" propagation="REQUIRED"/&gt; *" propagation="REQUIRED"/&gt; &lt;/beans&gt;

    struts2.3+hibernate3.6+spring3.1整合的纯xml配置的小项目

    *" read-only="true" /&gt; *" /&gt; *" propagation="NEVER" /&gt; --&gt; destroy-method="close"&gt; ${jdbc.driverClassName}" /&gt; ${jdbc.url}" /&gt; ${jdbc.username}" /&gt; ${jdbc....

    kotlin-web-maven-spring-thyme-secure-aes-encrypt-scrypt-encoded

    每个角色都有一个操作:USER = VIEW ONLY,ADMIN = READ / WRITE,SUPER = CREATE。 所有密码均使用AES加密,并使用scrypt编码,以确保密码强度高。 科技栈 Kotlin 专家 弹簧靴 百里香叶 引导程序 jQuery的 sockjs ...

    SSH第7章上机.zip ACCP8.0

    无需写hibernate的配置文件,而是将hibernate的配置直接加入到spring配置文件中 配置hibernate的映射文件地址 --&gt; &lt;value&gt;com/direct/domain/Employee.hbm.xml&lt;/value&gt; &lt;value&gt;...

    springmvcmybatis

    &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=... *" propagation="REQUIRED" read-only="true" /&gt; ...

    ssh框架在application.xml中配置数据源所需jar

    &lt;?xml version="1.0" encoding="UTF-8"?... *" read-only="true"/&gt; &lt;!-- 那些类的哪些方法参与事务 --&gt; (* com.longxian.drp.manager.*.*(..))" advice-ref="txAdvice"/&gt; &lt;/aop:config&gt; &lt;/beans&gt;

    SpringMVC+Hibernate全注解整合

    *" read-only="true" /&gt; *" propagation="REQUIRED" /&gt; *" propagation="REQUIRED" /&gt; *" propagation="REQUIRED" /&gt; *" propagation="REQUIRED" /&gt; &lt;!-- 这个映射配置主要是用来进行静态...

    Maven拆分代码.zip

    &lt;!--配置连接池--&gt; ... *" read-only="true"/&gt; *" propagation="REQUIRED"/&gt; &lt;!--配置切面--&gt; (* com.itheima.service.impl.*.*(..))"/&gt; &lt;aop:advisor advice-ref="advice" pointcut-ref=

    SpringMVC-SSH全注解

    import javax.persistence.Column... *" read-only="true" /&gt; *" propagation="REQUIRED" /&gt; *" propagation="REQUIRED" /&gt; *" propagation="REQUIRED" /&gt; *" propagation="REQUIRED" /&gt; &lt;/beans&gt;

    JTA事务源码示例

    Spring+iBatis+JOTM实现JTA事务: 如何处理跨库事物:spring + jtom 的jta事务是个很好的选择. 这个源码示例非常不错,包括所有的源码... *" read-only="true" rollback-for="Exception"/&gt; ...... ...... ......

    Numerical-Analysis-Hands-on-Experiments:上海科技大学 2018-2019 学年第二学期数值分析(GEMA1008)上机实验。Hands-on experiments of Numerical Analysis (GEMA1008) @ ShanghaiTech University, Spring 2019

    Numerical-Analysis-Hands-on-Experiments上海科技大学 2018-2019 学年第二学期数值分析(GEMA1008)上机实验。... This repository is archived and read-only since all work has been finished.

    Spring.Boot.in.Action.2015.12.pdf

    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"/&gt; &lt;/tx:advice&gt; //tx标签代表时间传播 &lt;aop:config&gt;//切入 (* com.cstp.service.*.*(..))"/&gt; &lt;aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice"/&gt; &lt;!-- ...

Global site tag (gtag.js) - Google Analytics