我想创建使用 JSF 和 Hibernate 的 Web 应用程序。我已经在本地创建了它,现在我想将它上传到 OpenShift 服务器。我是 JSF/Hibernate 的新手,我不知道如何配置它。有人可以写一些将 JSF 与 Hibernate 连接起来的可能性吗?它在本地工作,如下所示:
持久性.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>
负责连接mysql的代码:打包服务;
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();
}
}
}
还有其他一些与 Hibernate 连接的可能性吗?也许有人也知道我应该在 openshift git commit 之前将 persistence.xml 文件放在哪里?