Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nobodyiam/3db4bcaa5a694d26e2fcd08678cf39e2 to your computer and use it in GitHub Desktop.
Save nobodyiam/3db4bcaa5a694d26e2fcd08678cf39e2 to your computer and use it in GitHub Desktop.
public class OpenEntityManagerInViewInterceptor extends EntityManagerFactoryAccessor implements AsyncWebRequestInterceptor {
@Override
public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
if (!decrementParticipateCount(request)) {
EntityManagerHolder emHolder = (EntityManagerHolder)TransactionSynchronizationManager.unbindResource(getEntityManagerFactory());
logger.debug("Closing JPA EntityManager in OpenEntityManagerInViewInterceptor");
EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment