问题描述
-
我用maven(quickstart原型)创建了一个简单的Java项目
I got a simple java project created with maven (quickstart archetype)
我正在尝试为Drools会话配置JPA持久性(代码来自Drools文档)
I am trying to configure JPA persistence for drools sessions (the code comes from drools documentation)
-
我在我的pom.xml中添加了drools-persistence-jpa,Bitronix事务管理器和com.h2database依赖项
I added drools-persistence-jpa, Bitronix Transaction Manager and com.h2database dependencies to my pom.xml
我在Eclipse项目的"src/META-INF"中创建了一个META-INF文件夹作为Source-Folder
I created a META-INF folder as Source-Folder in my Eclipse Project in "src/META-INF"
我在那里添加了persistence.xml和jndi.properties文件.
I added the persistence.xml and jndi.properties file there.
在我的TestCase中,我有以下代码:
In my TestCase I have following code:
[...]EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.drools.persistence.jpa");[...]
[...]EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.drools.persistence.jpa");[...]
运行测试时,出现以下异常:
When running the test, I get the following Exception:
我相对确定,我创建META-INF或persistence.xml的方式存在一些问题(请参见下文).有什么建议吗?
I am relatively sure, that there's just something wrong with the way I created the META-INF or persistence.xml (see below). Any suggestions?
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
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
http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_1_0.xsd">
<persistence-unit name="org.drools.persistence.jpa" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/testDatasource</jta-data-source>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.drools.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.processinstance.ProcessInstanceEventInfo</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.connection.autocommit" value="true" />
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup" />
</properties>
</persistence-unit>
</persistence>
推荐答案
我认为问题与放置persistence.xml
文件的位置有关.您必须放置在src/main/resources/META-INF
或src/test/resources/META-INF
I think the problem is related to the place where you put your persistence.xml
file. Instead of src/META-INF
you must place is either in src/main/resources/META-INF
or src/test/resources/META-INF
已在您的persistence.xml文件中,您声明要使用org.hibernate.ejb.HibernatePersistence作为提供程序.根据您的评论,您没有将hibernate-entitymanager
作为依赖项包括在内.尝试添加该依赖性.
Edited:In your persistence.xml file you are stating that you want to use org.hibernate.ejb.HibernatePersistence as a provider. According to your comments, you are not including hibernate-entitymanager
as a dependency [source]. Try to add that dependency.
希望有帮助,
这篇关于JPA:配置持久性提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!