Class UnitOfWorkAspect


  • public class UnitOfWorkAspect
    extends Object
    An aspect providing operations around a method with the UnitOfWork annotation. It opens a Hibernate session and optionally a transaction.

    It should be created for every invocation of the method.

    Usage :

     
       UnitOfWorkProxyFactory unitOfWorkProxyFactory = ...
       UnitOfWork unitOfWork = ...         // get annotation from method.
    
       UnitOfWorkAspect aspect = unitOfWorkProxyFactory.newAspect();
       try {
         aspect.beforeStart(unitOfWork);
         ...                               // perform business logic.
         aspect.afterEnd();
       } catch (Exception e) {
         aspect.onError();
         throw e;
       } finally {
         aspect.onFinish();
       }
     
     
    • Constructor Detail

      • UnitOfWorkAspect

        public UnitOfWorkAspect​(Map<String,​org.hibernate.SessionFactory> sessionFactories)
    • Method Detail

      • beforeStart

        public void beforeStart​(@Nullable UnitOfWork unitOfWork)
      • afterEnd

        public void afterEnd()
      • onError

        public void onError()
      • onFinish

        public void onFinish()
      • configureSession

        protected void configureSession()
      • validateSession

        protected void validateSession()
      • getSession

        protected org.hibernate.Session getSession()
      • getSessionFactory

        protected org.hibernate.SessionFactory getSessionFactory()