Я просто не могу вставить объект EntityManagerFactory из ProfileDBUtil в класс ProfileManager, где я фактически применяю транзакции, чтобы искать запись в базе данных или обновлять строку и так далее.JPA createEntityManager NPE JtaStatusHelper.getStatus
метод createEntityManager() генерирует исключение, указанное в конце записи.
Странно то, что тот же кусок кода работает для среды UAT, пока он не работает для среды SIT. Все конфигурации одинаковы для обеих сред. Порядок загрузчика классов, общие ссылки lib, загрузчики классов модулей одинаковы. В обеих средах есть необходимые банки в своей файловой системе и, кажется, успешно загружаются во время выполнения.
В чем причина этой проблемы?
public class ProfileDBUtil {
private static final String PERSISTENCE_UNIT = "com.profile.userdb";
public boolean loadProfile(String memberID) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT);
ProfileManager upm = new ProfileManager(emf);
List <Profile> ProfileList = upm.searchProfile(memberID);
}
}
@SuppressWarnings("unchecked")
@JPAManager(targetEntity = com.profile.userdb.model.Profile.class)
public class ProfileManager {
private EntityManagerFactory emf;
public ProfileManager() {
}
public ProfileManager(EntityManagerFactory emf) {
this.emf = emf;
}
public void setEntityManagerFactory(EntityManagerFactory emf) {
this.emf = emf;
}
private EntityManager getEntityManager() {
if (emf == null) {
throw new RuntimeException("The EntityManagerFactory is null. This must be passed in to the constructor``");
}
return emf.createEntityManager(); // THIS FAILS
}
}
Log trace;
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:73)
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:115)
at org.hibernate.engine.transaction.internal.jta.CMTTransaction.join(CMTTransaction.java:149)
at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1207)
at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:176)
at org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:89)
at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:125)