问题描述
似乎将Play Framework 2.2.2与eBean ORM一起使用时,@ play.db.ebean.Transactional引发异常时不回滚事务.
It seems that when using Play Framework 2.2.2 with eBean ORM the @play.db.ebean.Transactionaldoes not rollback transaction when an Exception is thrown.
您中的某人是否了解此问题以及如何解决?
我看到eBean在其avaje-ebeanorm-agent 3.2.2中对此问题有一个BUG. : https://github.com/ebean-orm/avaje-ebeanorm/pull /44 (已在版本avaje-ebeanorm 3.2.3中修复)也播放2.2.2似乎使用avaje-ebeanorm-agent 3.2.2,当我将其更改为更高版本时,Built.scala(3.2.5)出现一些使用过的JPA注释的崩溃(例如,无法识别orphanRemoval)
I saw that eBean has a BUG about that issue in their avaje-ebeanorm-agent 3.2.2. : https://github.com/ebean-orm/avaje-ebeanorm/pull/44 which is fixed in version avaje-ebeanorm 3.2.3 Also play 2.2.2 seems use avaje-ebeanorm-agent 3.2.2 and when I change it to higher version in Built.scala (3.2.5) some crashes with the used JPA annotations appeared (like orphanRemoval is not recognised)
P.S.关于Play 2.1.1的讨论与此类似,播放2.1.1:无法使用ebean orm回滚事务,但未发现使用@Transactional in Action解决该问题的明确方法.
P.S. There is similar discussion with Play 2.1.1 , play 2.1.1: Unable to rollback transaction with ebean orm, but no clear resolving of the issue with using @Transactional in Action is found.
推荐答案
我遇到了类似的问题,但是我仅在播放版本2.3.7中进行了测试.:
I experienced similar problems, however I have only tested with play version 2.3.7.:
我注意到有两个包含事务注释的不同库:@com.avaje.ebean.annotation.Transactional
和@play.db.ebean.Transactional
.
I noticed that there are two different libs that contain the Transactional-annotation: @com.avaje.ebean.annotation.Transactional
and @play.db.ebean.Transactional
.
显然,它们每个只能在某种类型的类中工作,并且如果使用不当,将不会执行回滚.这是我通过测试发现的:
Apparently each of them only work in a certain type of classes and when used wrong, no rollback will be performed. This is what I found out by testing:
-
@com.avaje.ebean.annotation.Transactional
:仅适用于代表模型的类中的方法,即它们具有@javax.persistence.Entity
批注.但是,ebean增强中似乎存在一个错误,该错误导致类 - ebean的文档提供了另外两种实现交易的方式,例如您可以使用try/finally块.在我的测试中,这种方式一直很好,并且执行了回滚.
-
@play.db.ebean.Transactional
:仅适用于操作,即该类是从play.mvc.Controller
派生的.我不确定这种行为是否有意,但是有关播放框架的文档只谈论交易性的操作,根本没有提及模型类.
@com.avaje.ebean.annotation.Transactional
:only works for methods in classes that represent a model, i.e. they have the@javax.persistence.Entity
annotation. However there seems to be a bug in ebean enhancement, which causes the classes to always recompile although no changes were made- ebean's documentation gives two other ways of implementing transactions, e.g. you can use a try/finally block. In my tests this way has always worked well and a rollback was performed.
@play.db.ebean.Transactional
: only works for actions, i.e. the class is derived fromplay.mvc.Controller
. I'm not sure whether this behaviour is intended or not, but the documentation of play-framework only talks about transactional actions and doesn't mention model-classes at all.
这篇关于播放2.2.2 eBean的@Transactional不会在抛出异常时回滚事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!