Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JPA createEntityManager NPE JtaStatusHelper.getStatus_Java_Hibernate_Jpa_Nullpointerexception - Fatal编程技术网

Java JPA createEntityManager NPE JtaStatusHelper.getStatus

Java JPA createEntityManager NPE JtaStatusHelper.getStatus,java,hibernate,jpa,nullpointerexception,Java,Hibernate,Jpa,Nullpointerexception,我无法将EntityManagerFactory对象从ProfileDBUtil注入到ProfileManager类中,在该类中我实际应用事务以查找数据库中的条目,或更新行等 createEntityManager()方法引发在条目末尾指定的异常 奇怪的是,同一段代码对UAT环境有效,而对SIT环境无效。这两种环境的所有配置都相同。类装入器顺序、共享库引用、模块类装入器是相同的。 这两种环境在其文件系统中都有必要的JAR,并且似乎在运行时已成功加载 这个问题的根本原因是什么 public c

我无法将EntityManagerFactory对象从ProfileDBUtil注入到ProfileManager类中,在该类中我实际应用事务以查找数据库中的条目,或更新行等

createEntityManager()方法引发在条目末尾指定的异常

奇怪的是,同一段代码对UAT环境有效,而对SIT环境无效。这两种环境的所有配置都相同。类装入器顺序、共享库引用、模块类装入器是相同的。 这两种环境在其文件系统中都有必要的JAR,并且似乎在运行时已成功加载

这个问题的根本原因是什么

  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
     }

    }
公共类ProfileDBUtil{
私有静态最终字符串持久化\u UNIT=“com.profile.userdb”;
公共布尔加载配置文件(字符串成员ID){
EntityManagerFactory emf=Persistence.createEntityManagerFactory(Persistence_单位);
ProfileManager upm=新的ProfileManager(emf);
ListProfileList=upm.searchProfile(memberID);
}
}
@抑制警告(“未选中”)
@JPAManager(targetEntity=com.profile.userdb.model.profile.class)
公共类档案管理器{
私人实体管理工厂emf;
公共档案经理(){
}
公共档案管理器(EntityManagerFactory emf){
this.emf=emf;
}
public void setEntityManagerFactory(EntityManagerFactory emf){
this.emf=emf;
}
私有EntityManager getEntityManager(){
if(emf==null){
抛出新的RuntimeException(“EntityManagerFactory为null。必须将其传递给构造函数”`);
}
返回emf.createEntityManager();//此操作失败
}
}
日志跟踪

    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)
位于org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:73)
位于org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:115)
位于org.hibernate.engine.transaction.internal.jta.CMTTransaction.join(CMTTransaction.java:149)
位于org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1207)
位于org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:176)
位于org.hibernate.ejb.EntityManagerImpl.(EntityManagerImpl.java:89)
位于org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:125)
编辑尼尔;“JtaStatusHelper是一个休眠类!”我按响了门铃。我去检查了emf的道具,如下所示

Map<String, Object> prop = emf.getProperties();
logger.debug("emf props : " + prop.toString());
Map prop=emf.getProperties();
debug(“emf props:+prop.toString());
并观察SIT和UAT环境之间的差异。 基本的区别是openjpa在SIT道具的任何键中都不可用,而UAT却到处都有。SIT的配置不知何故变成了与hibernate相关的行。然而,根据JPA的设置,我把东西准备好后就出去了

它只是证明了最后一次将应用程序安装到服务器时出了问题。因此,我卸载了应用程序并从头开始安装。 它使事情变得正确