首页 > 解决方案 > 无法将 openliberty、JPA 与 Hibernate 集成

问题描述

我正在尝试使用 JPA、Hibernate 和 OpenLiberty 来开发 JakartaEE 应用程序。

我遵循了这份文件:https ://openliberty.io/guides/jpa-intro.html#configuring-jpa

就我而言,我希望使用 jpaContainer-2.2 或 jpa-2.2。

部分代码片段如下,

持久性.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence version="2.2"
    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_2.xsd">

    <persistence-unit name="jpaunit" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>jdbc/recruittimesdb</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.temp.use_jdbc_metadata_defaults" value="true" />
        </properties>
    </persistence-unit>

</persistence>

服务器.xml

<dataSource id="hibernatemysqldb"
        jndiName="jdbc/recruittimesdb">
        <jdbcDriver libraryRef="MySQLLib" />
        <properties databaseName="recruit_times_db"
            serverName="localhost" password="admin1234" user="root"
            serverTimezone="UTC" portNumber="3306" />
    </dataSource>

    <library id="MySQLLib">
        <file
            name="C:/Users/harsha/Documents/mysql-connector-java-8.0.19.jar" />
    </library>

    <library id="hibernate">
        <fileset dir="${config.dir}/hibernate/"
            includes="*.jar" />
    </library>

我仍然无法成功集成 Hibernate。很高兴看到一个有效的例子。

更新:

当服务器启动时,我收到此错误。

[INFO] [ERROR   ] CWWJP0015E: An error occurred in the org.hibernate.jpa.HibernatePersistenceProvider persistence provider when it attempted to create the container entity manager factory for the jpaunit 

持久性单元。发生以下错误:[PersistenceUnit: jpaunit] 无法构建 Hibernate SessionFactory

标签: javahibernatejpaopen-liberty

解决方案


推荐阅读