Explicit Savepoint

As an alternative to using transaction.setNestedUseSavepoint() we can instead explicitly create and use savepoints by obtaining the Connection from the transaction.

For example:

Customer newCustomer = new Customer();
newCustomer.setName("John");
newCustomer.save();

try (Transaction transaction = Ebean.beginTransaction()) {

  Connection connection = transaction.getConnection();
  // Create a Save Point
  Savepoint savepoint = connection.setSavepoint();

  newCustomer.setName("Doe");
  newCustomer.save();

  // Rollback to a specific save point
  connection.rollback(savepoint);
  transaction.commit();
}

Customer found = Ebean.find(Customer.class, newCustomer.getId());
System.out.println(found.getName()); // Prints "John"

Edit Page