我在EclipseLink實現中使用JPA,並使用Spring注入我的實體管理器工廠。我正在通過Eclipse測試我的應用程序和TomEE服務器(Tomcat + Java EE)。JPA正在連接到一個不存在的HSQL數據庫?
由於某些原因,當我讀取日誌時,似乎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的錯,因爲當我刪除HSQLDB-2.2。從它的lib目錄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
在您的項目源中搜索'data/hsqldb/hsqldb'。 – Antoniossss
在我的代碼中沒有提到該文件或數據庫Antoniossss,這是奇怪的事情:「data/hsqldb/hsqldb - 0匹配工作區」 – zootropo
嗯,這確實很奇怪。它必須在運行時類路徑中附帶某種插件或工具。 – Antoniossss