JPA Eclipselink 未连接到 HSQL Mysql

JPA Eclipselink connects to HSQL not Mysql

我正在使用 Eclipselink 学习 JPA,当我创建一个动态 Web 项目以将其与 JSF 一起使用时,独立程序运行正确并连接到 Mysql 数据库控制台显示:

[EL Info]: 2015-08-27 15:04:26.29--ServerSession(887216477)--Thread(Thread[http-bio-8080-exec-3,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.4.2.v20130514-5956486
[EL Fine]: 2015-08-27 15:04:26.824--Thread(Thread[http-bio-8080-exec-3,5,main])--Detected database platform: org.eclipse.persistence.platform.database.HSQLPlatform
[EL Config]: 2015-08-27 15:04:26.84--ServerSession(887216477)--Connection(23748817)--Thread(Thread[http-bio-8080-exec-3,5,main])--connecting(DatabaseLogin(
platform=>DatabasePlatform
user name=> ""
connector=>JNDIConnector datasource name=>null))
[EL Config]: 2015-08-27 15:04:26.841--ServerSession(887216477)--Connection(1638515369)--Thread(Thread[http-bio-8080-exec-3,5,main])--Connected: jdbc:hsqldb:file:D:\Projects\luna workspace\.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 Config]: 2015-08-27 15:04:26.842--ServerSession(887216477)--Connection(134525464)--Thread(Thread[http-bio-8080-exec-3,5,main])--connecting(DatabaseLogin(
platform=>HSQLPlatform
user name=> ""
connector=>JNDIConnector datasource name=>null))
[EL Config]: 2015-08-27 15:04:26.852--ServerSession(887216477)--Connection(239793705)--Thread(Thread[http-bio-8080-exec-3,5,main])--Connected: jdbc:hsqldb:file:D:\Projects\luna workspace\.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 Info]: 2015-08-27 15:04:27.137--ServerSession(887216477)--Thread(Thread[http-bio-8080-exec-3,5,main])--file:/D:/Projects/luna workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/fulltech/_fulltech login successful
[EL Warning]: 2015-08-27 15:04:27.14--ServerSession(887216477)--Thread(Thread[http-bio-8080-exec-3,5,main])--Problem while registering MBean: java.lang.NullPointerException
[EL Fine]: 2015-08-27 15:04:27.193--ServerSession(887216477)--Connection(1441030751)--Thread(Thread[http-bio-8080-exec-3,5,main])--SELECT ID, ACTIVATED, ACTIVATIONCODE, COUNTRY, EMAIL, PASSWORD FROM users
[EL Fine]: 2015-08-27 15:08:51.595--ServerSession(887216477)--Connection(840127246)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT ID, ACTIVATED, ACTIVATIONCODE, COUNTRY, EMAIL, PASSWORD FROM users

它连接到 HSQL 可能是 Eclipselink 的默认设置,这是 persistence.xml 我配置的连接

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
    <persistence-unit name="fulltech" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>fulltech.entity.User</class>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/db"/>
            <property name="javax.persistence.jdbc.user" value="user"/>
            <property name="javax.persistence.jdbc.password" value="pass"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> 
            <property name="eclipselink.logging.level" value="FINE"/>
       </properties>
    </persistence-unit>
</persistence>

我使用 TomEE。

由于您使用的是 JTA,persistence.xml 中的连接属性将被忽略。

您需要在应用程序服务器中设置数据源并在 <jta-data-source> 中提供。