interface javax.transaction.Synchronization{ public void beforeCompletion(); public void afterCompletion(int status); } The transaction manager provides asynchroniaztion protocal that allows the interested party to be notified before and after the transaction completes. Using the registerSynchronization method, the application server registers a Synchronization object for the transactin currently associated with the target Transaxtion object.
We can make it true as fallows:
public class TransactionSynchronization implements Synchronization { SessionFactory sessionFactory = null; public TransactionSynch(SessionFactory sessionFactory) { //code for checking the sessionFactory is valid or not this.sessionFactory = sessionFactory; }
public void beforeCompletion() { Session session .... //get session used sessionFactory //do somthing else and then try{ session.flush(); }catch(XXXException e){ } }
public void afterCompletion(int arg0) { closeTxManagedSession(sessionFactory); }
}
then we can use it that this: TransactionManager tm = (TransactionManager) ..look up tm.getTransaction().registerSynchronization( new TransactionSynchronization(sessionFactory));
interface javax.transaction.Synchronization{ public void beforeCompletion(); public void afterCompletion(int status);}The transaction manager provides asynchroniaztion protocal that allows the i...