创建EntityManager对象时出错

时间:2012-10-19 13:38:06

标签: weblogic openjpa

我正在尝试为持久性创建一个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".

请帮忙!

2 个答案:

答案 0 :(得分:0)

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

<persistence-unit name="Draco-PU">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
</persistence-unit>

答案 1 :(得分:0)

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

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