In the code where I create the DAO, I have an EntityManagerFactory, which I use to set the entityManager, As follows:
@PersistenceUnit
private EntityManagerFactory entityManagerFactory;
MyDAO dao = new MyDAOImpl();
dao. setEntityManager(entityManagerFactory.createEntityManager());
The problem is that when I do this, I get a Hibernate error:
Could not find UserTransaction in JNDI [java:comp/UserTransaction]
This is the spring entity manager factory configuration:
org.hibernate.transaction.JTATransactionFactory
com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
Switch to com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory, everything is normal.
< p>I have a JPA/Spring application that uses Hibernate as the JPA provider. In a part of the code, I have to manually create DAOs in my application using the new operator instead of using Spring DI. When I do this When doing this, Spring will not process the @PersistenceContext annotation.
In the code where I create the DAO, I have an EntityManagerFactory, and I use it to set the entityManager as follows:
< p>
@PersistenceUnit
private EntityManagerFactory entityManagerFactory;
MyDAO dao = new MyDAOImpl();
dao.setEntityManager(entityManagerFactory.createEntityManager());
The problem is that when I do this, I get a Hibernate error:
Could not find UserTransaction in JNDI [java:comp/UserTransaction]< /pre>This is the spring entity manager factory configuration:
org.hibernate.transaction.JTATransactionFactory
com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
It has nothing to do with EntityManager. This is a transaction configuration issue. Obviously, org.hibernate.transaction.JTATransactionFactory forces JNDI lookups.
< /p>
Switch to com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory, everything is normal.