Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openJPA's persistence.xml configuration

Tags:

openjpa

Earlier in my project I was using a combination of Hibernate 3.3.2, openJPA 2.1.1 to connect to the database and retrieve the information from table. Now I want to remove Hibernate and use openJPA for doing connection and retrieving the information.

My earlier configuration of persistence.xml was

<?xml version="1.0" encoding="UTF-8"?>
<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 persistence_2_0.xsd">
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
        <property name="hibernate.connection.url" value="jdbc:mysql://10.10.10.10:3306/test?autoReconnect=true"/>
        <property name="hibernate.connection.username" value="user"/>
        <property name="hibernate.connection.password" value="pwd"/>
        <property name="hibernate.generate_statistics" value="true"/>
        <property name="hibernate.cache.provider_class" value="org.hibernate.cache.OSCacheProvider"/>
        <property name="hibernate.cache.use_second_level_cache" value="true"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
        <property name="hibernate.c3p0.min_size" value="5"/>
        <property name="hibernate.c3p0.max_size" value="20"/>
        <property name="hibernate.c3p0.timeout" value="1800"/>
        <property name="hibernate.c3p0.max_statements" value="50"/>
        <property name="hibernate.c3p0.idle_test_period" value="1800"/>
        <property name="c3p0.idleConnectionTestPeriod" value="1810"/>
      </properties>
   </persistence-unit>
</persistence>

Now I want to move to openJPA 2.1.1 and for that my persistence.xml file is

<?xml version="1.0" encoding="UTF-8"?>
<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="TestOpenJPAPersistence" transaction-type="RESOURCE_LOCAL">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://10.10.10.10:3306/test?autoReconnect=true"/>
        <property name="javax.persistence.jdbc.user" value="user"/>
        <property name="javax.persistence.jdbc.password" value="pwd"/>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
        <property name="openjpa.ConnectionFactoryProperties" value="MaxActive=10,MaxIdle=5,MinIdle=2,MaxWait=1800000"/>
        <property name="openjpa.Log" value="File=E:\\temp\\TestOpenJPAPersistence\\org.apache.openjpa.log, DefaultLevel=DEBUG, Runtime=INFO, Tool=INFO, SQL=TRACE"/>
        <property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.MySQLDictionary"/>
        <property name="openjpa.DataCache" value="true"/>
        <property name="openjpa.QueryCache" value="true"/>
    </properties>
</persistence-unit>
</persistence>

My question is what are the replacement property for following hibernate property in openJPA

<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.OSCacheProvider"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.c3p0.min_size" value="5"/>
<property name="hibernate.c3p0.max_size" value="20"/>
<property name="hibernate.c3p0.timeout" value="1800"/>
<property name="hibernate.c3p0.max_statements" value="50"/>
<property name="hibernate.c3p0.idle_test_period" value="1800"/>

like image 511
Natraj Avatar asked Dec 09 '11 14:12

Natraj


1 Answers

After many trial and error I have found some replacement parameters. My present persistence.xml file looks like

persistence.xml:

<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<properties>
  <property name="openjpa.ConnectionURL" value="jdbc:mysql://xx.xx.xx.xx:3306/dbname"/>
  <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
  <property name="openjpa.ConnectionUserName" value="xxx"/>
  <property name="openjpa.ConnectionPassword" value="xxx"/>
  <property name="openjpa.DynamicEnhancementAgent" value="true"/>
  <property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>
  <property name="openjpa.Log" value="SQL=TRACE"/>
  <property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=60000"/>
</properties>

For connection pooling information check and for all OpenJPA Properties check

Hope this helps

like image 144
Natraj Avatar answered Nov 09 '22 15:11

Natraj