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 Sessions and transactions 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();
}
}
}