Skip to content

quarkiverse/quarkus-hibernate-types

Repository files navigation

Quarkus Hibernate Types

Build License Central

Warning

Quarkus 3.0 integrated Hibernate 6.2, so this extension is no longer needed for JSON type support.

We provide an updated version of this extension anyway, so it is more convenient to upgrade quarkus. It currently looks like that we will not implement any new features in this extension anymore, because hibernate 6.2 should bring you all of the features out of the box.

Introduction

This module integrates the hibernate extension "hibernate-types" into the quarkus universe, so you are able to support extra types that are not supported by the Hibernate ORM core.

For detailed information, check out the readme of the underlying repository: https://github.com/vladmihalcea/hypersistence-utils#readme

Detailed examples (including native image generation) can be found under the "integration-tests/simple" module.

Usage

To use this extension, add the following dependency to your project:

<dependency>
  <groupId>io.quarkiverse.hibernatetypes</groupId>
  <artifactId>quarkus-hibernate-types</artifactId>
</dependency>

Now you are able to define the newly added types in your already created entities, by including the "@TypeDef" annotation on your entity class and the "@Type" annotation on the desired json field.

import io.quarkiverse.hibernate.types.json.JsonBinaryType;
import io.quarkiverse.hibernate.types.json.JsonTypes;

/**
 * Declares a simple entity with a nested serialized object.
 * This object will get inserted into a "jsonb" (postgresql) column.
 */
@Entity
@TypeDef(name = JsonTypes.JSON_BIN, typeClass = JsonBinaryType.class)
public class MyEntity {

    /**
     * Unique identifier / primary key for this entity.
     */
    @Id
    private String id;

    /**
     * Nested parameter, that will get inserted into a json column
     */
    @Type(type = JsonTypes.JSON_BIN)
    @Column(name = "PARAM", columnDefinition = JsonTypes.JSON_BIN)
    private MyJsonParam param;

    /**
     * Parameter POJO
     */
    public static class MyJsonParam {
        private String id;
        private String name;
    }
    
}

Limitations

Hibernate Reactive Support

Using hibernate reactive is currently not (fully) supported, because the "hibernate-types" project isn't meant to be used by Hibernate Reactive (see https://quarkusio.zulipchat.com/#narrow/stream/187030-users/topic/quarkus-hibernate-types ).

The "types" notion needs to map to vendor specific types that some databases expose in their proprietary JDBC driver, but Hibernate Reactive doesn't use those drivers.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

All Contributors

Andrej Petras
Andrej Petras

💻 🚧
Werner Glanzer
Werner Glanzer

💻 🚧
Bruno Guimarães
Bruno Guimarães

💻

This project follows the all-contributors specification. Contributions of any kind welcome!