JPA Eclipselink连接到HSQL而不是Mysql

时间:2015-08-27 12:22:45

标签: jpa eclipselink

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

[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。

1 个答案:

答案 0 :(得分:2)

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

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

中提供