我正在使用JPA和EclipseLink实现,我使用Spring注入我的实体管理器工厂。我正在使用TomEE服务器(Tomcat + Java EE)通过Eclipse测试我的应用程序。
出于某种原因,当我阅读日志时,似乎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>
UPDATE :这似乎是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
答案 0 :(得分:2)
我找到了类似this 的内容。这意味着有嵌入式HSQLDB的eclipseLink版本,你可能已经得到了它。尝试在不使用HSQLDB的情况下调查并获取eclipseLink。