有誰知道如何手動創建EntityManagerFactory
?當我手動說,我的意思是它消耗一個特殊的persistence.xml
文件?這是我所嘗試過的,都使我失敗了。手動創建一個EntityManagerFactory?
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>
運行的Java代碼時,我碰到下面的錯誤。
ERROR :: org.hibernate.util.XMLHelper|Error parsing XML: XML InputStream(2) Document is invalid: no grammar found.
ERROR :: org.hibernate.util.XMLHelper|Error parsing XML: XML InputStream(2) Document root element "persistence", must match DOCTYPE root "null".
org.hibernate.MappingException: invalid mapping
這就像它正在尋找在persistence.xml
休眠特定的語法。我也嘗試了EJB3Configuration。它看起來像我的XML格式良好,這是爲什麼我得到這個錯誤。
你曾經能夠解決這個問題? – CMR 2011-07-29 21:22:05