0

I'm trying to use JPA, Hibernate with OpenLiberty to develop a JakartaEE Application.

I followed this document: https://openliberty.io/guides/jpa-intro.html#configuring-jpa

In my case, I'm hoping to use either jpaContainer-2.2 or jpa-2.2.

Some of the code snippets are as below,

persistence.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>

server.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>

I'm still not able to integrate Hibernate successfully. It would be great to see a working example.

UPDATE:

When the server starts up, I get this error.

[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 

persistence unit. The following error occurred: [PersistenceUnit: jpaunit] Unable to build Hibernate SessionFactory

Harsha Jayamanna
  • 2,148
  • 6
  • 25
  • 43
  • 2
    If you are using Hibernate with OpenLiberty you will want to use the `jpaContainer-2.2` feature (which just includes JPA integrations) and not the `jpa-2.2` feature (which includes JPA integrations + EclipseLink) – Andy Guibert Mar 27 '20 at 18:05
  • also, please update your question with the error you are seeing. Here is a pointer to the config needed: https://stackoverflow.com/a/47396524/3814029 – Andy Guibert Mar 27 '20 at 18:06
  • I tried this too https://stackoverflow.com/questions/47396310/open-liberty-and-hibernate/47396524#47396524, but no luck. – Harsha Jayamanna Mar 28 '20 at 02:36
  • hi @AndyGuibert, sorry for the late reply, is there a way to use Hibernate with javaee-8.0 ? or as you said earlier do I need to enable only jpaContainer-2.2 ? – Harsha Jayamanna Jul 13 '20 at 16:43
  • 1
    there isn't a way to use Hibernate with javaee-8.0 because it pulls in jpa-2.2 which pulls in EclipseLink. So yes you'd need to enable only jpaContianer-2.2 and any other specific features that your app needs – Andy Guibert Jul 13 '20 at 19:33
  • I was able to do it,https://www.harshajayamanna.com/2020/08/openliberty-jakartaee8-and-hibernate.html – Harsha Jayamanna Aug 02 '20 at 16:58

0 Answers0