Open liberty and Hibernate

Viewed 1976

Can I use Hibernate as JPA implementation in open-liberty? If such integration exists, I would presume that it comes with distributed caching and JTA?

1 Answers

Yes, in OpenLiberty we have the jpaContainer-2.1 feature, which provides only the JPA container integration code, and allows the user to plug in their own JPA 2.1 compliant implementation (i.e. EclipseLink or Hibernate).

Specifically for Hibernate, the jpaContainer-2.1 feature will integrate Hibernate with Liberty's transaction manager. See LibertyJtaPlatform

You can find full documentation here, including config examples:
Deploying a JPA application to Liberty

The basic config you will need in server.xml is the following:

<featureManager>
   <feature>jpaContainer-2.1</feature>
   <feature>bells-1.0</feature>
      ...    
</featureManager>    

<!-- Making a 'bell' for the library will register any META-INF/services in the referenced library with the Liberty runtime -->
<bell libraryRef="hibernate"/>

<!-- Include all of the hibernate jars in a shared lib -->
<library id="hibernate">
    <fileset dir="${server.config.dir}/hibernate/" includes="*.jar"/>
</library>

<!-- OPTIONAL: If you wish to directly reference hibernate APIs in your app, you will need to configure a shared library classloader -->
<application location="myApp.war">
   <classloader commonLibraryRef="hibernate"/>
</application>
Related