package persistence.util;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;

public class TransactionUtil {
	public static void doTransaction(EntityManagerFactory emf, Transaction t) {
		EntityManager em = emf.createEntityManager();
		EMInjectorConstraintValidatorFactory.setThreadLocalEntityManager(em);
		try{
			doTransaction(em, t);
		}finally {
			em.close();
		}
	}
	
	public static void doTransaction(EntityManager em, Transaction t) {
		EntityTransaction tx = null;
		try{
			tx = em.getTransaction();
			tx.begin();
				t.doTransation(em);
			tx.commit();
		} finally {
			if (tx != null && tx.isActive()) {
				tx.rollback();
			}
		}
	}
	
}

package persistence.util;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;

public class TransactionUtil {
	public static void doTransaction(EntityManagerFactory emf, Transaction t) {
		EntityManager em = emf.createEntityManager();
		EMInjectorConstraintValidatorFactory.setThreadLocalEntityManager(em);
		try{
			doTransaction(em, t);
		}finally {
			em.close();
		}
	}
	
	public static void doTransaction(EntityManager em, Transaction t) {
		EntityTransaction tx = null;
		EMInjectorConstraintValidatorFactory.setThreadLocalEntityManager(em);
		try{
			tx = em.getTransaction();
			tx.begin();
				t.doTransation(em);
			tx.commit();
		} finally {
			if (tx != null && tx.isActive()) {
				tx.rollback();
			}
		}
	}
	
}

Set thread local the entity manager in validatorfactory also in doTransaction with already created EntityManagers