I have a problem understanding how to work with ebean transactions in game 2.1.1.
Ebean.execute(txScope, new TxRunnable() {
public void run() {
Ebean.beginTransaction();
System.out.println("[**] : " + Ebean.currentTransaction());
User user = Ebean.find(User.class, 22);
user.setPassword("qweqwe125");
Ebean.save(user);
user = Ebean.find(User.class, 22);
user.setPassword("qweqwe126");
Ebean.rollbackTransaction();
}
But in this case, I get the error: PersistenceException: is the existing transaction still active?
Also I'm trying to do something like:
@Transactional(type=TxType.REQUIRES_NEW, isolation = TxIsolation.SERIALIZABLE)
public static void transactional2() {
User user = User.query.getById(22l);
user.setPassword("qweqwe123");
user.save();
Ebean.endTransaction();
}
In this case, I get updated values. Also in the last example, I will try rollback like this:. Ebean.currentTransaction () end ();
But get a NullPointerException error.
Can someone point me to a working example with transactions? Or write some example in the comments.
Thank.
UPDATE
As a result, we found a solution:
public static void transactional2() {
com.avaje.ebean.Ebean.beginTransaction();
User user = User.query.getById(22l);
user.setPassword("qweqwe123");
user.save();
com.avaje.ebean.Ebean.rollbackTransaction();
}
source
share