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
将JSF连接到Hibernate并上传到OpenShift_Hibernate_Jpa_Openshift - Fatal编程技术网

将JSF连接到Hibernate并上传到OpenShift

将JSF连接到Hibernate并上传到OpenShift,hibernate,jpa,openshift,Hibernate,Jpa,Openshift,我想创建使用JSF和Hibernate的web应用程序。我已经在本地创建了它,现在我想把它上传到OpenShift服务器。我是JSF/Hibernate新手,不知道如何配置它。有人能写一些连接JSF和Hibernate的可能性吗?它在本地工作,如下所示: persistence.xml <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/

我想创建使用JSF和Hibernate的web应用程序。我已经在本地创建了它,现在我想把它上传到OpenShift服务器。我是JSF/Hibernate新手,不知道如何配置它。有人能写一些连接JSF和Hibernate的可能性吗?它在本地工作,如下所示:

persistence.xml

<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="StudioBMPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>entity.article.Article</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="hibernate.connection.username" value="root"/>
      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
      <property name="hibernate.connection.password" value="root"/>
      <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/studiobm?zeroDateTimeBehavior=convertToNull"/>
    </properties>
  </persistence-unit>
</persistence>

是否有其他与Hibernate连接的可能性?也许有人也知道我应该在openshift git提交之前将persistence.xml文件放在哪里?

而不是直接在persistence.xml中指定连接值,您应该在文件中使用筛选和变量。在本地生成过程中,您将过滤开发值。要部署到OpenShift,您需要创建一个OpenShift配置文件,该文件定义了OpenShift的正确值。当您推到OpenShift并且应用程序得到构建时,OpenShift配置文件在默认情况下被激活

问题在于persistence.xml的配置错误。我使用EclipseLink连接数据库,问题是我使用javax.persistence.jdbc.*作为配置的名称空间。当我将其更改为eclipselink.jdbc.*时,应用程序终于开始工作。

谢谢,我理解你的意思,但我仍然不知道应该将persistence.xml放在OpenShift的何处。persistence.xml的位置没有更改。它进入META-INF。
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class DBManager {

    private static DBManager instance;
    private EntityManagerFactory emf;

    private DBManager() {}

    public synchronized static DBManager getManager() {
    if (instance == null) {
        instance = new DBManager();
    }

    return instance;
    }

    public EntityManagerFactory createEntityManagerFactory() {
    if (emf == null) {
        emf = Persistence.createEntityManagerFactory("StudioBMPU");
    }

    return emf;
    }

    public EntityManager createEntityManager() {
    return this.createEntityManagerFactory().createEntityManager();
    }

    public void closeEntityManagerFactory() {
    if (emf !=null) {
        emf.close();
    }
    }

}