You must be using ENHANCEMENT for @Transactional to work. That means you
must be enhancing the classes via IDE Plugin, Ant Task or javaagent. Refer to the
user guide for more details on enhancement.
Ebean can enhance your pojos to add transactional support. To do so put the
@Transaction annotation on a method or class. Ebean enhancement will then add
the supporting transactional logic (begin transaction, commit, rollback, suspend and resuming transactions etc).
...
// any old pojo
public class MyService {
@Transactional
public void runFirst() throws IOException {
// run in a Transaction (REQUIRED is the default)
// find a customer
Customer customer = Ebean.find(Customer.class, 1);
// call another "transactional" method
runInTrans();
}
@Transactional(type=TxType.REQUIRES_NEW)
public void runInTrans() throws IOException {
// run in its own NEW transaction
// ... suspend an existing transaction if required
// ... and resume it when this method ends
// find new orders
List<Order> orders = Ebean.find(Order.class)
.where().eq("status",OrderStatus.NEW)
.findList();
...
Put the @Transactional annotation on you methods and Ebean
can enhance the classes adding the Transactional management.
Standard transaction scope types
This supports the standard propagation rules of
REQUIRED (the default), REQUIRES_NEW, MANDATORY, SUPPORTS, NOT_SUPPORTS, NEVER.
These are an exact match of the EJB TransactionAttributeTypes.
Nested Transactions
Transactional methods can be nested as in the above example where
runFirst() calls runInTrans().
Isolation level and specific exception support
@Transactional (like Spring) supports isolation levels and explicit
handling of Exceptions (to rollback or not for specific exceptions).
Please refer to the User Guide for a more detailed explanation.
Interfaces
You can put @Transactional on interfaces and classes that
implement those interfaces will get the transactional enhancement.