Eclipselink忽略persistence.xml中的属性javax.persistence.jdbc.driver和javax.persistence.jdbc.url

时间:2018-12-21 17:32:37

标签: java orm eclipselink

我实际上正在将应用程序的所有组件更新为最新版本。因此,除其他外,我将从eclipselink-2.5.0升级到eclipselink-2.7.3,从Tomcat 7升级到TomEE。

我的持久性部门给我带来了麻烦。它只是忽略javax.persistence.jdbc.driverjavax.persistence.jdbc.url并以某种方式检测到HSQLPlatform数据库而不是我的MySQL数据库。

这是我的persistence.xml:

<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="DEV" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name='javax.persistence.jdbc.driver' value='com.mysql.jdbc.Driver' />      
      <property name='javax.persistence.jdbc.url' value='jdbc:mysql://xxxx.xxx.xxxx.xx.xx/xxxxx' />
      <property name='javax.persistence.jdbc.user' value='xxxxxx' />
      <property name='javax.persistence.jdbc.password' value='xxxxxx' />

      <!--  Optimization #14 - avoid auto flush cost on query execution -->
      <property name="eclipselink.persistence-context.flush-mode" value="commit" />
      <property name="eclipselink.cache.shared.default" value="false"/>

      <property name="eclipselink.logging.level" value="FINEST"/>

      <property name="eclipselink.connection-pool.default.initial" value="1" />
      <property name="eclipselink.connection-pool.node2.min" value="16"/>
      <property name="eclipselink.connection-pool.node2.max" value="16"/>
      <property name="eclipselink.connection-pool.node2.wait" value="300"/>
    </properties>
  </persistence-unit>

  ...

这是相关的日志输出:

[EL Finest]: 2018-12-21 11:49:35.543--ServerSession(774689836)--Thread(Thread[main,5,main])--Begin deploying Persistence Unit DEV; session /file:/C:/Java Workspace Photon/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/PES/WEB-INF/classes/_DEV; state Predeployed; factoryCount 2
[EL Finest]: 2018-12-21 11:49:35.588--ServerSession(774689836)--Thread(Thread[main,5,main])--property=eclipselink.target-server; value=org.apache.openejb.jpa.integration.eclipselink.OpenEJBServerPlatform
[EL Finest]: 2018-12-21 11:49:35.588--ServerSession(774689836)--Thread(Thread[main,5,main])--property=eclipselink.logging.level; value=FINEST; translated value=FINEST
[EL Finest]: 2018-12-21 11:49:35.588--ServerSession(774689836)--Thread(Thread[main,5,main])--property=eclipselink.logging.level; value=FINEST; translated value=FINEST
[EL Finest]: 2018-12-21 11:49:35.591--ServerSession(774689836)--Thread(Thread[main,5,main])--property=javax.persistence.jdbc.user; value=xxxxxx
[EL Finest]: 2018-12-21 11:49:35.591--ServerSession(774689836)--Thread(Thread[main,5,main])--property=javax.persistence.jdbc.password; value=xxxxxx
[EL Finest]: 2018-12-21 11:49:35.618--ServerSession(774689836)--Thread(Thread[main,5,main])--property=eclipselink.connection-pool.default.initial; value=1
[EL Finest]: 2018-12-21 11:49:35.618--ServerSession(774689836)--Thread(Thread[main,5,main])--property=eclipselink.connection-pool.node2.wait; value=300
[EL Finest]: 2018-12-21 11:49:35.618--ServerSession(774689836)--Thread(Thread[main,5,main])--property=eclipselink.connection-pool.node2.min; value=16
[EL Finest]: 2018-12-21 11:49:35.618--ServerSession(774689836)--Thread(Thread[main,5,main])--property=eclipselink.connection-pool.node2.max; value=16
[EL Finest]: 2018-12-21 11:49:35.618--ServerSession(774689836)--Thread(Thread[main,5,main])--property=eclipselink.cache.shared.default; value=false; translated value=false
[EL Info]: 2018-12-21 11:49:35.64--ServerSession(774689836)--Thread(Thread[main,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.7.3.v20180807-4be1041
[EL Finest]: 2018-12-21 11:49:35.656--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.oracle.Oracle12Platform, regular expression: (?is)oracle.*12.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.oracle.Oracle11Platform, regular expression: (?is)oracle.*11.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.oracle.Oracle10Platform, regular expression: (?is)oracle.*10.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.oracle.Oracle9Platform, regular expression: (?is)oracle.*9.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.Oracle12Platform, regular expression: (?is)core.oracle.*12.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.Oracle11Platform, regular expression: (?is)core.oracle.*11.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.Oracle10Platform, regular expression: (?is)core.oracle.*10.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.Oracle9Platform, regular expression: (?is)core.oracle.*9.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.oracle.OraclePlatform, regular expression: (?is)oracle.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.SQLAnywherePlatform, regular expression: SQL\ Anywhere.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.SybasePlatform, regular expression: (?i)(sybase.*)|(adaptive\ server\ enterprise.*)|(SQL\ Server.*)
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.SQLServerPlatform, regular expression: (?i)microsoft.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.JavaDBPlatform, regular expression: (?i).*derby.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.DB2ZPlatform, regular expression: (?i).*db2.*dsn.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.DB2MainframePlatform, regular expression: (?i).*(db2|AS).*(AS/400|qsq).*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.DB2Platform, regular expression: (?i).*db2.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.PointBasePlatform, regular expression: (?is)pointbase.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.MySQLPlatform, regular expression: (?i)mysql.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.Informix11Platform, regular expression: (?i)(informix.*)|(ids.*)
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.PostgreSQLPlatform, regular expression: (?is)postgresql.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.H2Platform, regular expression: (?is)h2.*
[EL Finest]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Database platform: org.eclipse.persistence.platform.database.HSQLPlatform, regular expression: (?is)hsql.*
[EL Fine]: 2018-12-21 11:49:35.657--Thread(Thread[main,5,main])--Detected database platform: org.eclipse.persistence.platform.database.HSQLPlatform
[EL Config]: 2018-12-21 11:49:35.674--ServerSession(774689836)--Connection(1116906950)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
    platform=>DatabasePlatform
    user name=> "xxxxxx"
    connector=>JNDIConnector datasource name=>null
))
[EL Config]: 2018-12-21 11:49:35.675--ServerSession(774689836)--Connection(1823071136)--Thread(Thread[main,5,main])--Connected: jdbc:hsqldb:file:C:\Java Workspace Photon\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\data\hsqldb\hsqldb
    User: SA
    Database: HSQL Database Engine  Version: 2.3.2
    Driver: HSQL Database Engine Driver  Version: 2.3.2
[EL Finest]: 2018-12-21 11:49:35.675--ServerSession(774689836)--Connection(1785609933)--Thread(Thread[main,5,main])--Connection acquired from connection pool [read].
[EL Finest]: 2018-12-21 11:49:35.675--ServerSession(774689836)--Connection(1785609933)--Thread(Thread[main,5,main])--Connection released to connection pool [read].
[EL Config]: 2018-12-21 11:49:35.675--ServerSession(774689836)--Connection(8105698)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
    platform=>HSQLPlatform
    user name=> "xxxxxx"
    connector=>JNDIConnector datasource name=>null
))

日志中显示的用户名/密码正确,但是我不知道它尝试连接的位置。

这是怎么回事?

1 个答案:

答案 0 :(得分:0)

TomEE的默认数据源是HSQL DB,它是内存数据库,可在TomEE中使用。您的配置对于TomEE不正确。因此,TomEE使用默认的HSQL DB数据源而不是您的DB。您必须定义数据源属性才能在TomEE中连接数据库。您可以参考以下链接。

JPA persistence.xml I want it to connect to MariaDB but it always connects to hsqldb

http://tomee.apache.org/datasource-config.html

http://tomee.apache.org/configuring-datasources-in-tests.html

我希望以上详细信息能够解决您的问题。