I have a project where I would like to use Hibernate for database access. In the application, the JPA api is used.
The persistence.xml file is this
<persistence
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="hibernate.test"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.ejb.cfgfile" value="/hibernate/hibernate.cfg.xml"/>
</properties>
</persistence-unit>
</persistence>
The hibernate.cfg.xml file is the following
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@//server:1521/DBNAME</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<!-- <property name="hibernate.hbm2ddl.auto">verify</property> -->
<property name="hibernate.default_catalog">SYS_SOMETHING</property>
<property name="hibernate.default_schema">SYS_SOMETHING</property>
</session-factory>
</hibernate-configuration>
The problem is with this setup, that the entityManagerFactory = Persistence.createEntityManagerFactory("hibernate.test");
call takes about 25 seconds to complete.
If I move the configuration directly to the persistence.xml file, the connection completes in 1 second. The error occurs with both Oracle and MySQL databases.
I can see the delay in the log file, nothing else is happening during this time
525 [pool-2-thread-1] INFO org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
21668 [pool-2-thread-1] DEBUG org.hibernate.service.internal.JaxbProcessor - cfg.xml document did not define namespaces; wrapping in custom event reader to introduce namespace information
Complete log: http://pastebin.com/4NjPpFPe
This delay is only about 200ms if the cfg.xml is not used.
During this time, there process memory does not change, the cpu use is at 0% and there are 0 interactions according to sysinternals Process Monitor.
I would like to keep this setup because hibernate.cfg.xml is used for reverse engineering and hibernate tools also.
Tools used: java8 hibernate-4.3.8 ojdbc7 jpa-2.1
Thank you for any suggestions in advance.
Update:
Found the solution, now I'm a happy man!
The hibernate framework (or the xml parser, I'm not sure) would wait on a http request.
To fix the problem, replace
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
with
<!DOCTYPE hibernate-configuration SYSTEM "-//Hibernate/Hibernate Configuration DTD 3.0//EN">