问题描述
在我们的应用程序中进行loadtesting时,我注意到如果您使用@Transactional和@Cacheable,hibernate始终会创建数据库事务。有没有简单的方法来防止这种情况?
在春季内解决这个问题的一个更加灵活的方法是拥有以下类/接口:
$ b
- Servicelayer接口
- 缓存注释类,它只是一个代理/转发给
- 交易注释实现类
会发生以下情况
致电1:
- 创建交易
- 类方法被调用
- 结果缓存&返回
致电2:
- 交易获得创建
- 缓存的结果得到返回
首选结果应该是:
致电1:
- 创建交易
- 类方法被调用
- 结果缓存&返回
致电2:
$ b
- 返回结果
您需要更改 @的相对顺序Transactional 和 @Cacheable 方面。
可以使用<$ c $ < tx:annotation-driven> 和< cache:annotation-driven>的 code>。请参阅为订单价值的含义。
While doing loadtesting on our application I noticed that if you use @Transactional and @Cacheable annotions that hibernate always creates a database transaction. Is there an easy way to prevent this? A more eleberate way to solve this within spring is to have following class/interfaces
- Servicelayer-interface
- Cacheable annotated class which is just a proxy/forward to
- Transactional annotation implentation class
What happens is the following
Call 1:
- Transaction gets created
- class method gets called
- result cached & returned
Call 2:
- Transaction gets created
- Cached result gets returned
The prefered result should be:
Call 1:
- Transaction gets created
- class method gets called
- result cached & returned
Call 2:
- Cached result gets returned
You need to change relative order of @Transactional and @Cacheable aspects.
It can be configured using order attribute of <tx:annotation-driven> and <cache:annotation-driven>. See 8.2.4.7 Advice ordering for the meaning of order values.
这篇关于组合hibernate @Transactional& ehcache @Cacheable总是创建数据库事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!