All Implemented Interfaces:
org.hibernate.metamodel.mapping.BasicValuedMapping, org.hibernate.metamodel.mapping.Bindable, org.hibernate.metamodel.mapping.JdbcMappingContainer, org.hibernate.metamodel.mapping.MappingModelExpressible, org.hibernate.metamodel.mapping.SqlExpressible, org.hibernate.metamodel.mapping.ValueMapping, org.hibernate.metamodel.model.domain.DomainType<Object>, org.hibernate.query.BindableType<Object>, org.hibernate.query.sqm.SqmExpressible<Object>, org.hibernate.type.descriptor.java.JavaTypedExpressible, org.hibernate.usertype.DynamicParameterizedType, org.hibernate.usertype.ParameterizedType, org.hibernate.usertype.UserType<Object>

JsonType allows you to map any given JSON object (e.g., POJO, Map<String, Object>, List<T>, JsonNode) on any of the following database systems:

  • PostgreSQL - for both jsonb and json column types
  • MySQL - for the json column type
  • SQL Server - for the NVARCHAR column type storing JSON
  • Oracle - for the JSON column type if you're using Oracle 21c or the VARCHAR column type storing JSON if you're using an older Oracle version
  • H2 - for the json column type

If you switch to Oracle 21c from an older version, then you should also migrate your JSON columns to the native JSON type since this binary type performs better than VARCHAR2 or BLOB column types.

However, if you don't want to migrate to the new JSON data type, then you just have to provide the column type via the JPA Column.columnDefinition() attribute, like in the following example:

 @Type(JsonType.class)
 @Column(columnDefinition = "VARCHAR2")
 

For more details about how to use the JsonType, check out this article on vladmihalcea.com.

If you are using Oracle and want to store JSON objects in a BLOB column type, then you can use the JsonBlobType instead. For more details, check out this article on vladmihalcea.com.

Or, you can use the JsonType, but you'll have to specify the underlying column type using the JPA Column.columnDefinition() attribute, like this:

 @Type(JsonType.class)
 @Column(columnDefinition = "BLOB")
 
Author:
Vlad Mihalcea
  • Field Details

    • INSTANCE

      public static final JsonType INSTANCE
  • Constructor Details

    • JsonType

      public JsonType()
    • JsonType

      public JsonType(Type javaType)
    • JsonType

      public JsonType(JsonConfiguration configuration)
    • JsonType

      public JsonType(org.hibernate.type.spi.TypeBootstrapContext typeBootstrapContext)
    • JsonType

      public JsonType(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    • JsonType

      public JsonType(ObjectMapperWrapper objectMapperWrapper)
    • JsonType

      public JsonType(com.fasterxml.jackson.databind.ObjectMapper objectMapper, Type javaType)
    • JsonType

      public JsonType(ObjectMapperWrapper objectMapperWrapper, Type javaType)
  • Method Details

    • getName

      public String getName()