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

@@ -568,16 +568,89 @@
  null;%0D%0A
+%09%09EMInjectorConstraintValidatorFactory.setThreadLocalEntityManager(em);%0D%0A
 %09%09try%7B%0D%0A

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