我正在使用:
TomEE 7.0 + EclipseLink + Vaadin(+ Vaadin JPA)+ Maven
当我在Eclipse内的服务器上运行我的应用程序时,TomEE忽略persistence.xml
中定义的数据库参数。即使我定义了eclipselink.target-database
属性
的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>
控制台上的结果显示TomEE 读取参数并尝试创建连接但因此连接到HSQL 而不是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].
有什么奇怪的。 如果我使用Eclipse中的Export -> WAR file
将应用程序导出到独立的.WAR 并在同一个TomEE实例上手动部署,它的行为正确且连接到PostgreSQL < / p>
此处描述了类似的问题:
答案 0 :(得分:2)
创建/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>
然后尝试