Code example for EntityManagerHolder

Methods: getEntityManager

0
     */ 
    public static EntityManager resolveEntityManager(EntityManagerFactory entityManagerFactory) { 
        EntityManagerHolder entityManagerHolder = 
                (EntityManagerHolder) TransactionSynchronizationManager.getResource(entityManagerFactory); 
        if (entityManagerHolder != null) { 
            return entityManagerHolder.getEntityManager(); 
        } 
        return entityManagerFactory.createEntityManager(); 
    } 
 
    public static void closeNonTransactionalEntityManager(EntityManager entityManager) { 
        if (entityManager == null) { 
            return; 
        } 
        boolean isTransactional = TransactionSynchronizationManager.hasResource(entityManager.getEntityManagerFactory()); 
        if (isTransactional) { 
            entityManager.close(); 
        } 
    } 
 
Contextual code suggestions in your IDE  Get Codota for Java