组合hibernate @Transactional& ehcache @Cacheable总是创建数据库事务 [英] Combination hibernate @Transactional & ehcache @Cacheable always creates DB transaction

查看:125
本文介绍了组合hibernate @Transactional& ehcache @Cacheable总是创建数据库事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用程序中进行loadtesting时,我注意到如果您使用@Transactional和@Cacheable,hibernate始终会创建数据库事务。有没有简单的方法来防止这种情况?
在春季内解决这个问题的一个更加灵活的方法是拥有以下类/接口:
$ b


  • Servicelayer接口

  • 缓存注释类,它只是一个代理/转发给
  • 交易注释实现类


会发生以下情况



致电1:


  1. 创建交易

  2. 类方法被调用

  3. 结果缓存&返回

致电2:


  1. 交易获得创建

  2. 缓存的结果得到返回

首选结果应该是:

致电1:


  1. 创建交易

  2. 类方法被调用

  3. 结果缓存&返回

致电2:
$ b


  1. 返回结果


解决方案

您需要更改 @的相对顺序Transactional @Cacheable 方面。

可以使用<$ c $ < tx:annotation-driven> < cache:annotation-driven>的 code>。请参阅 8.2.4.7意见排序为订单价值的含义。


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:

  1. Transaction gets created
  2. class method gets called
  3. result cached & returned

Call 2:

  1. Transaction gets created
  2. Cached result gets returned

The prefered result should be:

Call 1:

  1. Transaction gets created
  2. class method gets called
  3. result cached & returned

Call 2:

  1. 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&amp; ehcache @Cacheable总是创建数据库事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆