Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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
在带有嵌入式Derby的Ubuntu上的Netbeans平台应用程序中,JPA调用createEntityManager()时出现问题_Jpa_Derby_Ubuntu 12.04_Netbeans Platform_Javadb - Fatal编程技术网

在带有嵌入式Derby的Ubuntu上的Netbeans平台应用程序中,JPA调用createEntityManager()时出现问题

在带有嵌入式Derby的Ubuntu上的Netbeans平台应用程序中,JPA调用createEntityManager()时出现问题,jpa,derby,ubuntu-12.04,netbeans-platform,javadb,Jpa,Derby,Ubuntu 12.04,Netbeans Platform,Javadb,更新2:在VMWare player上的Ubuntu 12.04虚拟机上进行了测试,所以问题可能出在我的Ubuntu工作站上 更新1: 我在Windows7上进行了测试,安装的版本在那里运行,所以我将其作为错误报告提交给netbeans。 原始问题 当我从NetBeans 7.2 IDE中启动使用JPA和嵌入式Derby的我的应用程序时,它会工作,但是当我为Ubuntu 12.04创建linux安装程序并安装时,安装的应用程序不会在Derby主目录中创建我的数据库,我将其设置为System.g

更新2:在VMWare player上的Ubuntu 12.04虚拟机上进行了测试,所以问题可能出在我的Ubuntu工作站上

更新1: 我在Windows7上进行了测试,安装的版本在那里运行,所以我将其作为错误报告提交给netbeans。

原始问题

当我从NetBeans 7.2 IDE中启动使用JPA和嵌入式Derby的我的应用程序时,它会工作,但是当我为Ubuntu 12.04创建linux安装程序并安装时,安装的应用程序不会在Derby主目录中创建我的数据库,我将其设置为
System.getProperty(“user.home”)

基本上,它在IDE中工作得很好,但在启动nb平台部署版本时,我在获取实体管理器时遇到了问题。我尝试过使用sudo进行安装,它默认为/usr/local/myapp,并且还将install dir的数据库权限临时更改为777,但这没有帮助。似乎没有任何日志目录来查看可能失败的内容。我担心异常或错误消息会被Netbeans平台吃掉

希望NetBeans平台或嵌入式derby人员能够分享一些关于故障排除的建议

这是我的persistence.xml,它是我的netbeans平台应用程序中包装好的jar

<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="VmCfgLibPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>mycompany.jpa.Vmcfg</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby:myDB;create=true"/>
      <property name="javax.persistence.jdbc.password" value="app"/>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
      <property name="javax.persistence.jdbc.user" value="app"/>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

是否引发异常?应用程序中似乎成功执行的最后一行代码是什么,应用程序中似乎失败的第一行代码是什么?这一行代码是要调用的最后一行:em=Persistence.createEntityManagerFactory(“VmCfgLibPU”).createEntityManager();消息信息(“em是”+em);永远不会被执行。没有抛出我能看到的异常:(顺便说一句,我在Windows7上测试了这一点,它成功了。我想这是linux或ubuntu上的安装程序的问题。听起来你并没有真正接触到Derby部分,而是陷入了JPA部分,所以我恐怕没有更多的建议,因为我不太了解JPA。
public class Util {

    static public EntityManager getEm() {
        return getEntityManager();
    }

    static public EntityManager em;

    static public EntityManager getEntityManager() {
        if (em == null || em.isOpen() == false) {
            try {
                File homeDir = new File(System.getProperty("user.home")+"/.simdriver");
                homeDir.mkdirs();
                Msg.info("home dir is: "+homeDir.getAbsolutePath());
                System.setProperty("derby.system.home", homeDir.getAbsolutePath());
                EntityManagerFactory emf 
                      = Persistence.createEntityManagerFactory("VmCfgLibPU");
                Msg.info("Check B2");
                System.out.println("Check B2");

                // .createEntityManager() does not execute when formally installed
                // works when running in IDE
                em = emf.createEntityManager();
                Msg.info("Check C2");
                System.out.println("Check C2");
            } catch (Exception e) {
                Exceptions.printStackTrace(e);
                Msg.err("Error while getting entity manager");
            }
        }
        return em;
    }
}