Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Custom Hibernate ORM and Hibernate Search on WildFly Swarm

 

March 1, 2018
Carlos Esteban Feria Vila
Related topics:
Java
Related products:
Developer Tools

Share:

    This article will show how to use a custom version of Hibernate (Hibernate ORM and Hibernate Search) on a WildFly Swarm Java application. I won't give details about the WildFly Swarm configuration, if you need more information you can take a look at the WildFly Swarm User's Guide.

    WildFly Swarm includes fractions for Hibernate ORM and Hibernate Search.
    You can add those fractions using:

    <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>jpa</artifactId>
    </dependency>
    <dependency>
     <groupId>org.wildfly.swarm</groupId>
     <artifactId>hibernate-search</artifactId>
    </dependency>

    Unfortunately, WildFly Swarm doesn't use the latest versions of Hibernate ORM and Hibernate Search, so you won't be able to use some functionalities of Hibernate that are just available on latest versions. For instance, the latest version of Hibernate Search offers the capability to integrate Elasticsearch. For more information go to the Hibernate Search documentation.

    Solution

    • Create a WildFly Swarm application. You can use the WildFly Swarm generator, JBoss Forge, or choose another option.
    • Add WildFly Swarm fractions (Hibernate Search and ORM) to your project:
    <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>datasources</artifactId>
    </dependency>
    <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>hibernate-search</artifactId>
    </dependency>
    • Add maven-dependency-plugin to your pom.xml:
    <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <id>unpack</id>
                <phase>generate-resources</phase>
                <goals>
                    <goal>unpack</goal>
                </goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>org.hibernate</groupId>
                            <artifactId>hibernate-orm-modules</artifactId>
                            <version>5.2.12.Final</version>
                            <classifier>wildfly-11-dist</classifier>
                            <type>zip</type>
                            <overWrite>false</overWrite>
                            <outputDirectory>${project.build.outputDirectory}/modules</outputDirectory>
                        </artifactItem>
                        <artifactItem>
                            <groupId>org.hibernate</groupId>
                            <artifactId>hibernate-search-modules</artifactId>
                            <version>5.8.2.Final</version>
                            <classifier>wildfly-11-dist</classifier>
                            <type>zip</type>
                            <overWrite>false</overWrite>
                            <outputDirectory>${project.build.outputDirectory}/modules</outputDirectory>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </execution>
        </executions>
    </plugin>

    This will add Hibernate modules to the folder /modules of your project (WildFly Swarm will detect all modules under the /modules folder). For more information about how to use Hibernate modules, take a look at Hibernate ORM at WildFly and Hibernate Search at WildFly

    • Add persistence.xml to your project and then add Hibernate properties:
    <property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2.12.Final"/>
    
    <property name="wildfly.jpa.hibernate.search.module" value="org.hibernate.search.orm:5.8.2.Final"/>

     

    That's all, now you have you own version of Hibernate on your WildFly Swarm Application. If you want to see the code, here is a repo with a complete example: https://github.com/carlosthe19916/wildfly-swarm-hibernate

    Warning:

    The example runs on any version of WildFly Swarm Application except for 2017.12.0, because of recent bugs resolved on 2018.1.0.

    If you have any questions about this post, please let me know!!

    Last updated: February 6, 2024

    Recent Posts

    • Cloud bursting with confidential containers on OpenShift

    • Reach native speed with MacOS llama.cpp container inference

    • A deep dive into Apache Kafka's KRaft protocol

    • Staying ahead of artificial intelligence threats

    • Strengthen privacy and security with encrypted DNS in RHEL

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue