OSGI + Aries JPA + Hibernate Dialect

366 views Asked by At

I'm trying to make some pax-exam-karaf tests (hibernate 5.2.6, Pax-exam 4.9.2, ServiceMix 7.0.0M3) but I have a problem with hibernate dialect. In production we use PostgreSQL but for integration tests I would like to use h2 database. Our persistence xml contains

<property name="hibernate.dialect" value="${hibernate.dialect.value}" 

In maven parent POM we defined

<hibernate.dialect.value>org.hibernate.dialect.PostgreSQLDialect</hibernate.dialect.value>

I have read this discussion http://karaf.922171.n3.nabble.com/Dynamic-parameters-in-persistence-xml-td4043602.html and tried it in Pax-Exam configuration code :

for (String persistenceUnit : persistenceUnits) {
      puOptions.add(KarafDistributionOption.editConfigurationFilePut("etc/org.apache.aries.jpa." + persistenceUnit + ".cfg",
              "hibernate.dialect", "org.hibernate.dialect.H2Dialect"));
}

So I can see these configuration files in karaf/etc directory but all persistence bundles still have a hibernate.dialect that is specified in persistence.xml. I have also tried to copy one of this file to servicemix distribution but with the same result, hibernate dialect is still the same.

Is there something wrong with this solution with aries jpa persistence configuration files? Or is there any other way how to change dialect for persistence.xml?

I know that I can remove hibernate dialect from persistence.xml but from some other reason we cannot do that. I also found that I can use my own resolver for dialect (http://blog.exxeta.com/2016/03/23/dynamically-resolve-hibernate-database-dialect/) but I would prefer a way with configuration if it is possible.

0

There are 0 answers