Java 是否手动创建EntityManagerFactory?
是否有人知道如何手动创建Java 是否手动创建EntityManagerFactory?,java,xml,hibernate,jpa,Java,Xml,Hibernate,Jpa,是否有人知道如何手动创建EntityManagerFactory?当我说手动时,我的意思是让它使用一个特殊的persistence.xml文件?这是我尝试过的,但一切都失败了 Configuration configuration = new Configuration(); InputStream is = JPAUtil.class.getResourceAsStream("/s-persistence.xml"); configuration.addInputStream(is); _en
EntityManagerFactory
?当我说手动时,我的意思是让它使用一个特殊的persistence.xml
文件?这是我尝试过的,但一切都失败了
Configuration configuration = new Configuration();
InputStream is = JPAUtil.class.getResourceAsStream("/s-persistence.xml");
configuration.addInputStream(is);
_entityManagerFactory = Persistence.createEntityManagerFactory(
puType.persistenceName, configuration.getProperties());
s-persistence.xml
看起来像:
<?xml version="1.0"?>
<persistence version="1.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_1_0.xsd">
<persistence-unit name="S_DATABASE" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property value="false" name="hibernate.show_sql"/>
<property value="org.hibernate.dialect.OracleDialect" name="hibernate.dialect"/>
<property value="oracle.jdbc.driver.OracleDriver" name="hibernate.connection.driver_class "/>
<property value="jdbc:oracle:thin:@xxx.xxx.xxx.xxx:TEST" name="hibernate.connection.url"/>
<property value="TESTOWNER" name="hibernate.connection.username"/>
<property value="TEST" name="hibernate.connection.password"/>
<property value="2" name="hibernate.connection.isolation"/>
</properties>
</persistence-unit>
</persistence>
就像它在
persistence.xml
中寻找特定于hibernate的语法一样。我还尝试了ejb3配置。看起来我的XML格式很好,这让我不明白为什么会出现这个错误。我认为您遇到了
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
可能无法访问,因此无法对XML文件进行验证
尽量不要像这样给出架构位置:
<persistence xmlns="http://java.sun.com/xml/ns/persistence">
谢谢你的建议。但即使在做了更改之后,我仍然会得到相同的准确错误。现在,我的persistence.xml文件的顶部看起来像你建议的那样。你有没有解决过这个问题?
<persistence xmlns="http://java.sun.com/xml/ns/persistence">