Code example for EntityManagerHolder

0
        boolean isNewEm = false; 
        if (em == null) { 
            logger.debug("Creating new EntityManager for JpaInterceptor invocation"); 
            em = createEntityManager(); 
            isNewEm = true; 
            TransactionSynchronizationManager.bindResource(getEntityManagerFactory(), new EntityManagerHolder(em)); 
             
            //For new EM store as attribute so it can be closed 
            context.setExecutionAttribute(ENTITY_MANAGER_FACTORY, em); 
        } 
         
        context.setExecutionAttribute(IS_NEW, isNewEm); 
    } 
 
    @Override 
    public void postExecution(HttpServletRequest request, HttpServletResponse response, IPortletExecutionContext context, Exception e) { 
        boolean isNewEm = (Boolean)context.getExecutionAttribute(IS_NEW); 
        if (isNewEm) { 
            TransactionSynchronizationManager.unbindResource(getEntityManagerFactory()); 
            EntityManager em = (EntityManager)context.getExecutionAttribute(ENTITY_MANAGER_FACTORY);