Manually creating an EntityManagerFactory?

Does anyone know how to create EntityManagerFactorymanually? When I speak manually, I mean that it uses a special file persistence.xml? This is what I tried and it all let me down.

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 as follows:

<?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>

When running java code, the following error appears.

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

This is similar to finding sleep mode syntax in persistence.xml. I also tried EJB3Configuration. It looks like my XML is well-formed, which throws me aside why I am getting this error.

+3
source share
1 answer

I think you are faced with a problem that

http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd

may not be available, therefore, checking the XML file for it cannot be performed.

Try not to specify the location of the circuit as follows:

<persistence xmlns="http://java.sun.com/xml/ns/persistence">
0
source

All Articles