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

1

7

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.

Washery answered 1/4, 2014 at 19:50 Comment(0)
S
7

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.
Sanctify answered 26/1, 2015 at 18:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.