Play 2.2.2 @Transactional of eBean does not rollback transaction in Exception thrown

一个人想着一个人 提交于 2019-12-12 11:05:29

问题


It seems that when using Play Framework 2.2.2 with eBean ORM the @play.db.ebean.Transactional does not rollback transaction when an Exception is thrown.

Does someone of you know something about the issue and how it could be solved ?

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


回答1:


I experienced similar problems, however I have only tested with play version 2.3.7.:

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: 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 from play.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.


来源:https://stackoverflow.com/questions/22795548/play-2-2-2-transactional-of-ebean-does-not-rollback-transaction-in-exception-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!