TomEE in Eclipse always uses HSQL Database Engine instead of defined in persistence.xml (EclipseLink)

639 views Asked by At

I am using:

TomEE 7.0 + EclipseLink + Vaadin (+ Vaadin JPA) + Maven

When I am running my app on server inside the Eclipse, TomEE ignores my DB params defined in persistence.xml. It always uses build-in HSQL Database Engine even if i define eclipselink.target-database property

persistence.xml:

 <persistence-unit name="OFFERTER_JPA"
    transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <non-jta-data-source>OFFERTER_DS</non-jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.PostgreSQLPlatform"/>
        <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/oferter" />
        <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
        <property name="javax.persistence.jdbc.user" value="oferter" />
        <property name="javax.persistence.jdbc.password" value="oferter" />
        <property name="eclipselink.logging.level" value="ALL" />
    </properties>
</persistence-unit>

The result on console shows that TomEE reads the params and tries to create connection but as a result connects to HSQL instead of PostgreSQL:

[EL Info]: 2015-06-22 14:54:23.491--ServerSession(1776533395)--Thread(Thread[http-bio-8080-exec-9,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.6.0.v20150309-bf26070
[EL Config]: 2015-06-22 14:54:23.501--ServerSession(1776533395)--Connection(1077694737)--Thread(Thread[http-bio-8080-exec-9,5,main])--connecting(DatabaseLogin(
    platform=>PostgreSQLPlatform
    user name=> "oferter"
    connector=>JNDIConnector datasource name=>null
))
cze 22, 2015 2:54:23 PM org.hsqldb.persist.Logger logInfoEvent
INFO: checkpointClose start
cze 22, 2015 2:54:24 PM org.hsqldb.persist.Logger logInfoEvent
INFO: checkpointClose end
[EL Config]: 2015-06-22 14:54:24.073--ServerSession(1776533395)--Connection(2047991763)--Thread(Thread[http-bio-8080-exec-9,5,main])--Connected: jdbc:hsqldb:file:C:\Programowanie\workspace\java\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\data\hsqldb\hsqldb
    User: SA
    Database: HSQL Database Engine  Version: 2.3.2
    Driver: HSQL Database Engine Driver  Version: 2.3.2
[EL Finest]: 2015-06-22 14:54:24.073--ServerSession(1776533395)--Connection(933531057)--Thread(Thread[http-bio-8080-exec-9,5,main])--Connection acquired from connection pool [read].
[EL Finest]: 2015-06-22 14:54:24.074--ServerSession(1776533395)--Connection(933531057)--Thread(Thread[http-bio-8080-exec-9,5,main])--Connection released to connection pool [read].

What is strange. If I export the application to standalone .WAR using Export -> WAR file from Eclipse and deploy it by hand on the same TomEE instance, it behaves correctly and connects to PostgreSQL

Similar problem is described here:

The same problem description - no solution

1

There are 1 answers

1
user5039266 On BEST ANSWER

create /WEB-INF/resources.xml

<?xml version="1.0" encoding="UTF-8"?>
<tomee>

  <Resource id="myDS" type="DataSource">
    JdbcDriver  = org.postgresql.Driver
    JdbcUrl = jdbc:postgresql://112.216.148.236:5432/ncore
    UserName  =  xxx
    Password  = xxx
</Resource>
</tomee>

and then try