Exemplo n.º 1
0
 @Override
 protected Object proceed(MethodInvocation invocation) throws Throwable {
   invocation.proceed();
   if (invocation.didThrowCheckedException()) {
     invocation.rethrow();
   }
   return invocation.getReturnValue();
 }
  @Override
  public void advise(MethodInvocation invocation) {
    Session session = manager.getSession();

    Transaction transaction = session.beginTransaction();

    try {
      invocation.proceed();

      // Note: as per EJB specs, a checked exception is still considered
      // success, and the transaction still commits.

      transaction.commit();
    } catch (RuntimeException e) {
      transaction.rollback();

      throw e;
    }
  }