当前位置: 首页 > 知识库问答 >
问题:

正在获取CWWJP0050E:无法找到持久性提供程序组织。冬眠ejb。冬眠持久性

狄子真
2023-03-14

我正在用JPA创建一个EJB应用程序。我创建了EJBBean,它在实体管理器中使用@PersistenceContext。我还提供了持久化中的设置。包含Hibernate信息的xml文件。我试图使用transaction type=JTA,并试图使用JNDI访问数据源。我还在服务器上提供了一些信息。Websphere Liberty的xml文件

但是,我收到了一条错误消息-

javax。ejb。EJBException:CWNEN0030E:服务器无法获取java:comp/env/SolarUniversityJpa引用的对象实例。例外信息是:java。lang.RuntimeException:CWWJP0050E:无法找到持久性提供程序组织。冬眠ejb。冬眠持久性。;嵌套的例外是:java。RuntimeException:java。lang.RuntimeException:CWWJP0050E:无法找到持久性提供程序组织。冬眠ejb。冬眠持久性。

请参考Server.xml文件后提到的错误消息以了解更多信息

Servlet

@WebServlet("/StudentServlet")
public class StudentServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @EJB
    StudentEjbBean studentEjbBean;

    public StudentServlet() {
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        studentEjbBean.testJpa();
    }

}

埃比安

@Stateless
@LocalBean
public class StudentEjbBean {

    @PersistenceContext(name="SolarUniversityJpa")
    EntityManager entityManager;

    public StudentEjbBean() {
    }

    public void testJpa()
    {
        StudentDao studentDao = new StudentDaoImpl();
        studentDao.SaveInformation(entityManager);
    }
}

坚持不懈xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="SolarUniversityJpa"
        transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:global/env/jdbc/MySql</jta-data-source>
        <class>com.student.entity.StudentEntity</class>
        <properties>
            <property name="connection.driver_class" value="com.mysql.jdbc.Driver" />
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/SolarUniversity" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="hibernate.hbm2ddl.auto" value="create" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
        </properties>
    </persistence-unit>
</persistence>

Server.xml

<server description="new server">
    <!-- Enable features -->
    <featureManager>
        <feature>webProfile-7.0</feature>
        <feature>localConnector-1.0</feature>
    </featureManager>

    <!-- To access this server from a remote client add a host attribute to 
        the following element, e.g. host="*" -->
    <httpEndpoint httpPort="9080" httpsPort="9443"
        id="defaultHttpEndpoint" />

    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true" />

    <applicationMonitor updateTrigger="mbean" />

    <jdbcDriver id="mySqlEmbedded" libraryRef="mySqlLib" />
    <library id="mySqlLib" filesetRef="mySqlFileSet" />
    <fileset id="mySqlFileSet" dir="E:/Backups"
        includes="mysql-connector-java-5.1.34.jar" />

    <dataSource id="jdbc/samplejpadatasource" jndiName="jdbc/MySql"
        jdbcDriverRef="mySqlEmbedded">
        <properties user="root" password="root"
            URL="jdbc:mysql://localhost:3306/SolarUniversity">
        </properties>
    </dataSource>

    <enterpriseApplication id="SolarUniversityEAR"
        location="SolarUniversityEAR.ear" name="SolarUniversityEAR">
        <!-- <classloader commonLibraryRef="MySQLLib" /> -->
    </enterpriseApplication>
</server>

例外信息

    [ERROR   ] CNTR0019E: EJB threw an unexpected (non-declared) exception during invocation of method "testMessage". Exception data: javax.ejb.EJBException: CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/SolarUniversityJpa reference.  The exception message was: java.lang.RuntimeException: CWWJP0050E: Unable to locate persistence provider org.hibernate.ejb.HibernatePersistence.; nested exception is: java.lang.RuntimeException: java.lang.RuntimeException: CWWJP0050E: Unable to locate persistence provider org.hibernate.ejb.HibernatePersistence.
        at com.ibm.ejs.container.util.ExceptionUtil.EJBException(ExceptionUtil.java:461)
        at [internal classes]
        at com.ejb.stateless.student.EJSLocalNSLStudentEjbBean_58c656c8.testMessage(EJSLocalNSLStudentEjbBean_58c656c8.java)
        at com.servlet.student.StudentServlet.doPost(StudentServlet.java:56)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1290)
        at [internal classes]
    Caused by (repeated) ... : java.lang.RuntimeException: java.lang.RuntimeException: CWWJP0050E: Unable to locate persistence provider org.hibernate.ejb.HibernatePersistence.
        at com.ibm.ws.jpa.management.JPAPUnitInfo.getEntityManagerFactory(JPAPUnitInfo.java:960)
        ... 7 more
    Caused by: java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence
        at com.ibm.ws.classloading.internal.AppClassLoader.findClassCommonLibraryClassLoaders(AppClassLoader.java:499)
        ... 1 more

    [ERROR   ] SRVE0777E: Exception thrown by application class 'com.ibm.ejs.container.util.ExceptionUtil.EJBException:461'
    javax.ejb.EJBException: CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/SolarUniversityJpa reference.  The exception message was: java.lang.RuntimeException: CWWJP0050E: Unable to locate persistence provider org.hibernate.ejb.HibernatePersistence.; nested exception is: java.lang.RuntimeException: java.lang.RuntimeException: CWWJP0050E: Unable to locate persistence provider org.hibernate.ejb.HibernatePersistence.
        at com.ibm.ejs.container.util.ExceptionUtil.EJBException(ExceptionUtil.java:461)
        at [internal classes]
        at com.ejb.stateless.student.EJSLocalNSLStudentEjbBean_58c656c8.testMessage(EJSLocalNSLStudentEjbBean_58c656c8.java)
        at com.servlet.student.StudentServlet.doPost(StudentServlet.java:56)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1290)
        at [internal classes]
    Caused by (repeated) ... : java.lang.RuntimeException: java.lang.RuntimeException: CWWJP0050E: Unable to locate persistence provider org.hibernate.ejb.HibernatePersistence.
        at com.ibm.ws.jpa.management.JPAPUnitInfo.getEntityManagerFactory(JPAPUnitInfo.java:960)
        ... 7 more
    Caused by: java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence
        at com.ibm.ws.classloading.internal.AppClassLoader.findClassCommonLibraryClassLoaders(AppClassLoader.java:499)
        ... 1 more

    [ERROR   ] SRVE0315E: An exception occurred: java.lang.Throwable: javax.ejb.EJBException: CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/SolarUniversityJpa reference.  The exception message was: java.lang.RuntimeException: CWWJP0050E: Unable to locate persistence provider org.hibernate.ejb.HibernatePersistence.; nested exception is: java.lang.RuntimeException: java.lang.RuntimeException: CWWJP0050E: Unable to locate persistence provider org.hibernate.ejb.HibernatePersistence.
        at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:5000)
        at [internal classes]
    Caused by: javax.ejb.EJBException: CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/SolarUniversityJpa reference.  The exception message was: java.lang.RuntimeException: CWWJP0050E: Unable to locate persistence provider org.hibernate.ejb.HibernatePersistence.; nested exception is: java.lang.RuntimeException: java.lang.RuntimeException: CWWJP0050E: Unable to locate persistence provider org.hibernate.ejb.HibernatePersistence.
        at com.ibm.ejs.container.util.ExceptionUtil.EJBException(ExceptionUtil.java:461)
        at [internal classes]
        at com.ejb.stateless.student.EJSLocalNSLStudentEjbBean_58c656c8.testMessage(EJSLocalNSLStudentEjbBean_58c656c8.java)
        at com.servlet.student.StudentServlet.doPost(StudentServlet.java:56)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1290)
        ... 1 more
    Caused by (repeated) ... : java.lang.RuntimeException: java.lang.RuntimeException: CWWJP0050E: Unable to locate persistence provider org.hibernate.ejb.HibernatePersistence.
        at com.ibm.ws.jpa.management.JPAPUnitInfo.getEntityManagerFactory(JPAPUnitInfo.java:960)
        ... 7 more
    Caused by: java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence
        at com.ibm.ws.classloading.internal.AppClassLoader.findClassCommonLibraryClassLoaders(AppClassLoader.java:499)
        ... 1 more

共有2个答案

方兴旺
2023-03-14

谢谢安迪·吉伯特的建议。这可能对其他人有帮助。下面是我如何解决这些问题的。

关于问题1:

我采用了安迪说的方法。

对于问题2:

[ERROR]CNTR0020E:EJB在bean“BeanId(SolarUniverSityYear#SolarUniversityEjb.jar#StudentEjb”上调用方法“testMessage”时引发了意外(未声明)异常‌​异常数据:java.lang.AbstractMethodError:org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManag‌​er(Ljavax/persistenc)‌​e/同步类型‌​ELjava/util/Map;)Lj‌​avax/persistence/Ent‌​IT经理;

下载了支持JPA2.1的新版Hibernate。在这之后,我又遇到了另一个问题

第三期:

CNTR0020E: EJB在bean BeanId(SolarUniversityEAR#SolarUniversityEjb.jar#StudentEjbBean,null)上调用方法testMessage时抛出了一个意外(未声明)异常。异常数据:java.lang.NullPointerExcture

为了解决这个问题,我在持久性中添加了以下代码。xml(因为我使用的是transaction type=“JTA”)。这是特定于WebSphere Liberty的。资料来源:7.5.9。组织。冬眠服务jta。站台spi。JTA平台

<property name="hibernate.transaction.jta.platform" 
value="org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform" />

最后,我能够将信息保存在数据库中。

葛昕
2023-03-14

异常消息表示找不到Hibernate类。这是预期的,因为Liberty在jpa-2.0(OpenJPA)或jpa-2.1(eclipselink)特性中不提供Hibernate类。

如果您想在Liberty中使用Hibernate,您需要自己下载Hibernate JAR,并将其包含在应用程序中,或者配置一个共享库。

假设您已经在位置C:/hibernate上有Hibernate jars,您可以将以下内容添加到您的server.xml

<library id="HibernateLib">
  <fileset dir="C:/hibernate" includes="*.jar"/>
</library>

然后向应用程序提供共享库,如下所示:

<enterpriseApplication id="SolarUniversityEAR" location="SolarUniversityEAR.ear" name="SolarUniversityEAR">
     <classloader commonLibraryRef="HibernateLib"/>
</enterpriseApplication>

此外,这里还有一个有用的示例:
Liberty JPA Hibernate Sample

 类似资料:
  • 我需要你帮我把冬眠映射成一对多我不知道为什么这是错的 另一类: 映射 另一个映射: Hibernate配置 这就是错误: 如果有人能帮我,我非常感激,谢谢!

  • 我正在尝试从当前用户那里获取特定租金的列表。 控制器中的代码: account\u id是外键。 运行后,我发现错误: 我做错了什么?

  • 我想写一个简单的不存在的地方子句HQL查询。我不熟悉Hibernate,我有一些小问题。 我的查询如下所示: 我想选择所有包含IDUser当天购买的门票的天数。所有这些都与id为IDFest的节日相关。 我的堆栈跟踪: 映射类: Day.java Festivals.java 门票。Java语言

  • 我正在尝试使用JPA和EclipseLink来持久化元素。所以我创建了一个类来持久化 等等。我创建了一个类来“使用”: 然后,我有以下persistence.xml: 但是,即使我改变了属性,我也有同样的错误: 线程"main"中的异常javax.persistence.PeristenceException:没有名为MyPU的EntityManager的持久性提供程序(当调用工厂=Persist

  • 我得到这个错误的原因很奇怪。我将解释这个错误是按时间顺序排列的,以便更容易理解。 这是我的JPA查询,在我添加po之前,它一直工作得很好。it的customer\u id。 商店订单构造器 错误: 我很困惑为什么我调用的表中的一列不被识别。我已经玩了一段时间了,但感觉就像在追我的尾巴。 -------更新------- 我注意到表中的其他BigInt变量在构造函数中很长。因此,我将customer

  • 另一种方法是使用Crieteria关联,但关联只能与和一起工作! 请在这里帮帮我。