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?
Asked
Active
Viewed 2,201 times
1 Answers
7
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>

Andy Guibert
- 41,446
- 8
- 38
- 61
-
Thanks Andy, the only thing I am still unclear about is the configuration of Hibernate's second level cache. Typically this is is done with Infinispan, or in case of Payara - nazelcast. How is this done in OpenLiberty? – Hristo Stoyanov Nov 20 '17 at 22:38
-
@HristoStoyanov I have not configured Hibernate's session factory cache before, but if I had to guess... you will need to provide your own implementation (for instance Ehcache) since I don't think youll find one in OpenLiberty. Then add it to the shared library in your server config and set the persistence properties Hibernate needs. – Will Dazey Nov 21 '17 at 15:39
-
Thanks Will,I figured that I had to do something like that – Hristo Stoyanov Nov 21 '17 at 21:48
-
Will configurations be the same if I'm using jpaContainer-2.2? – Harsha Jayamanna Mar 27 '20 at 10:02