1

我将 JPA 与 EclipseLink 实现结合使用,并使用 Spring 注入我的实体管理器工厂。我正在通过 Eclipse 使用 TomEE 服务器(Tomcat + Java EE)测试我的应用程序。

出于某种原因,当我阅读日志时,似乎 JPA 正在连接到我的 Oracle 数据库,但也连接到我没有在任何地方配置的 HSQL 数据库。

[EL Config]: 2013-10-24 13:05:48.515--ServerSession(24468517)--Connection(222262)--Thread(Thread[localhost-startStop-1,5,main])--connecting(DatabaseLogin(
    platform=>OraclePlatform
    user name=> ""
    connector=>JNDIConnector datasource name=>null
))
[EL Config]: 2013-10-24 13:05:49.062--ServerSession(24468517)--Connection(30536968)--Thread(Thread[localhost-startStop-1,5,main])--Connected: jdbc:hsqldb:file:data/hsqldb/hsqldb
    User: SA
    Database: HSQL Database Engine  Version: 2.2.8
    Driver: HSQL Database Engine Driver  Version: 2.2.8
[EL Finest]: 2013-10-24 13:05:49.062--ServerSession(24468517)--Connection(19789489)--Thread(Thread[localhost-startStop-1,5,main])--Connection acquired from connection pool [read].
[EL Finest]: 2013-10-24 13:05:49.062--ServerSession(24468517)--Connection(19789489)--Thread(Thread[localhost-startStop-1,5,main])--Connection released to connection pool [read].
[EL Config]: 2013-10-24 13:05:49.062--ServerSession(24468517)--Connection(10424924)--Thread(Thread[localhost-startStop-1,5,main])--connecting(DatabaseLogin(
    platform=>OraclePlatform
    user name=> ""
    connector=>JNDIConnector datasource name=>null
))
[EL Config]: 2013-10-24 13:05:49.062--ServerSession(24468517)--Connection(9702992)--Thread(Thread[localhost-startStop-1,5,main])--Connected: jdbc:hsqldb:file:data/hsqldb/hsqldb
    User: SA
    Database: HSQL Database Engine  Version: 2.2.8
    Driver: HSQL Database Engine Driver  Version: 2.2.8

我知道我的配置肯定有什么问题,但我不知道是什么。

这是我的persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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="pu" transaction-type="JTA">
            <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>


            <properties>
                <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform" />
                <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver" />

                <property name="eclipselink.logging.level" value="FINEST" />
                <property name="eclipselink.logging.parameters" value="true" />
                <property name="eclipselink.logging.level.sql" value="FINEST" />
            </properties>
        </persistence-unit>
</persistence>

这是我的 applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd">

    <jee:jndi-lookup id="dataSource" jndi-name="myPool" />

    <bean id="emFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="loadTimeWeaver">
            <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManagerName" value="java:comp/env/comp/TransactionManager"/>
    </bean>

    <context:component-scan base-package="com.example" />
    <jpa:repositories base-package="com.example.model.dao" />
</beans>

更新:这似乎是 TomEE 的错,因为当我从其 lib 目录中删除 hsqldb-2.2.8.jar 时,我在日志中收到此错误:

INFO: Configuring Service(id=myPool, type=Resource, provider-id=ProvidedByTomcat)
oct 24, 2013 2:23:05 PM org.apache.openejb.assembler.classic.Assembler createRecipe
INFO: Creating Resource(id=myPool)
oct 24, 2013 2:23:05 PM org.apache.openejb.config.AutoConfig deploy
INFO: Configuring PersistenceUnit(name=pu, provider=org.eclipse.persistence.jpa.PersistenceProvider)
oct 24, 2013 2:23:05 PM org.apache.openejb.config.ConfigurationFactory configureService
INFO: Configuring Service(id=Default JDBC Database, type=Resource, provider-id=Default JDBC Database)
oct 24, 2013 2:23:05 PM org.apache.openejb.config.AutoConfig logAutoCreateResource
INFO: Auto-creating a Resource with id 'Default JDBC Database' of type 'DataSource for 'pu'.
oct 24, 2013 2:23:05 PM org.apache.openejb.assembler.classic.Assembler createRecipe
INFO: Creating Resource(id=Default JDBC Database)
oct 24, 2013 2:23:05 PM org.apache.tomee.catalina.TomcatWebAppBuilder startInternal
SEVERE: Unable to deploy collapsed ear in war StandardEngine[Catalina].StandardHost[localhost].StandardContext[/dauro]
org.apache.xbean.propertyeditor.PropertyEditorException: Unable to resolve class org.hsqldb.jdbcDriver
4

1 回答 1

2

我发现了类似的东西。这意味着存在嵌入式 HSQLDB 的 eclipseLink 版本,您可能已经明白了。尝试在没有 HSQLDB 的情况下调查并获取 eclipseLink。

于 2013-10-24T11:41:48.873 回答