HIBERNATE  |  Register  | 
      SEARCH: 
   
News 
Features 
Documentation 
   Related Projects 
   External Documentation 
Download 
Forum & Mailinglists 
Support 
JIRA Issue Tracking
Wiki Community Area


JBoss.org



middlegen

JIRA Issue Tracking




      
Documentation > Community Area > AspectJ Hibernate aspect

AspectJ Hibernate aspect

In order to not need to close explicitly hibernate sessions, one can use AOP to handle this by adding a "persistent" aspect to business objects.

This could be done using the following aspect (which uses the Thread Local Session pattern discussed in this area), developed with AspectJ:

public aspect HibernateAspect {

    pointcut transactionalInvocation(): execution(* test.server..*.*(..));
    
    Object around(): transactionalInvocation() && !cflowbelow(transactionalInvocation()) {
        try {
            return proceed();
        } finally {
            HibernateSession.closeSession();
        }
    }
}
      

coWiki web collaboration