0

我正在尝试为持久性创建一个 EntityManager 对象,但我无法创建 EntityManager 对象。请在下面找到示例代码:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("Draco-PU");
EntityManager em = emf.createEntityManager();

我也在 persistence.xml 文件中定义了持久性单元名称。

<persistence-unit name="Draco-PU" >

持久化 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="Draco-PU" >
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>DracoDataSource</jta-data-source>
<non-jta-data-source>DracoUnmanagedDataSource</non-jta-data-source>
<class>dk.tdc.soa.smo.draco.db.model.DslServiceEntity</class>
<class>dk.tdc.soa.smo.draco.db.model.DslServiceCatalogEntity</class>
<class>dk.tdc.soa.smo.draco.db.model.History</class>
<class>dk.tdc.soa.smo.draco.db.model.ConfigEntity</class>
<properties>
  <property name="openjpa.Log" value="DefaultLevel=WARNING, Runtime=WARNING, Tool=WARNING, SQL=WARNING" />
  <!-- <property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.OracleDictionary" />  -->     
  <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
</properties>
</persistence-unit>
</persistence>

面临的错误是:

javax.persistence.PersistenceException: No Persistence provider for EntityManager
named Draco-PU: Provider named kodo.persistence.PersistenceProviderImpl threw 
expected exception at create EntityManagerFactory:
org.apache.openjpa.persistence.PersistenceException<openjpa-1.1.1-SNAPSHOT-
r422266:891341 fatal general error>  
org.apache.openjpa.persistence.PersistenceException: There was an error when invoking
the static newInstance method on the named factory class 
"kodo.jdbc.kernel.KodoJDBCBrokerFactory".

请帮忙!

4

2 回答 2

0

在您的 WEB-INF 文件夹中创建下一个结构:classes/META-INF,将您的 persistence.xml 文件放入并重新启动服务器。

Weblogic 在构建目录中查找该文件。

于 2013-11-28T00:03:39.797 回答
0

您是否在persistence.xml 的“persistence-unit”元素中声明了“provider”元素?它应该看起来像这样:

<persistence-unit name="Draco-PU">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
</persistence-unit>
于 2012-10-20T05:01:04.567 回答