All Implemented Interfaces:
jakarta.persistence.metamodel.BasicType<Object>, jakarta.persistence.metamodel.Type<Object>, 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.BasicDomainType<Object>, org.hibernate.metamodel.model.domain.DomainType<Object>, org.hibernate.metamodel.model.domain.ReturnableType<Object>, org.hibernate.metamodel.model.domain.SimpleDomainType<Object>, org.hibernate.query.sqm.SqmBindableType<Object>, org.hibernate.query.sqm.SqmExpressible<Object>, org.hibernate.query.sqm.tree.domain.SqmDomainType<Object>, org.hibernate.type.BindableType<Object>, org.hibernate.type.descriptor.java.JavaTypedExpressible, org.hibernate.type.OutputableType<Object>, 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
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.hibernate.metamodel.mapping.Bindable

    org.hibernate.metamodel.mapping.Bindable.JdbcValuesBiConsumer<X extends Object,Y extends Object>, org.hibernate.metamodel.mapping.Bindable.JdbcValuesConsumer

    Nested classes/interfaces inherited from interface org.hibernate.usertype.DynamicParameterizedType

    org.hibernate.usertype.DynamicParameterizedType.ParameterType

    Nested classes/interfaces inherited from interface jakarta.persistence.metamodel.Type

    jakarta.persistence.metamodel.Type.PersistenceType
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final JsonType
     

    Fields inherited from interface org.hibernate.usertype.DynamicParameterizedType

    ACCESS_TYPE, ENTITY, IS_DYNAMIC, IS_PRIMARY_KEY, PARAMETER_TYPE, PROPERTY, RETURNED_CLASS, XPROPERTY
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    JsonType(JsonConfiguration configuration)
     
    JsonType(ObjectMapperWrapper objectMapperWrapper)
     
    JsonType(ObjectMapperWrapper objectMapperWrapper, Type javaType)
     
    JsonType(Type javaType)
     
    JsonType(org.hibernate.type.spi.TypeBootstrapContext typeBootstrapContext)
     
    JsonType(tools.jackson.databind.ObjectMapper objectMapper)
     
    JsonType(tools.jackson.databind.ObjectMapper objectMapper, Type javaType)
     
  • Method Summary

    Modifier and Type
    Method
    Description
     

    Methods inherited from class io.hypersistence.utils.hibernate.type.MutableDynamicParameterizedType

    canDoExtraction, extract, extract, getJdbcType, getPersistenceType, getSqmType, setParameterValues

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.hibernate.metamodel.model.domain.BasicDomainType

    getJavaType

    Methods inherited from interface org.hibernate.metamodel.mapping.BasicValuedMapping

    addToCacheKey, getJdbcMapping, getJdbcTypeCount, getSingleJdbcMapping

    Methods inherited from interface org.hibernate.metamodel.mapping.Bindable

    forEachDisassembledJdbcValue, forEachDisassembledJdbcValue, forEachDisassembledJdbcValue, forEachJdbcType, forEachJdbcValue, forEachJdbcValue, forEachJdbcValue, forEachJdbcValue

    Methods inherited from interface org.hibernate.metamodel.model.domain.DomainType

    getExpressibleJavaType

    Methods inherited from interface org.hibernate.query.sqm.SqmBindableType

    resolveExpressible

    Methods inherited from interface org.hibernate.query.sqm.tree.domain.SqmDomainType

    getTupleLength, getTypeName

    Methods inherited from interface org.hibernate.query.sqm.SqmExpressible

    getExpressibleJavaType, getRelationalJavaType

    Methods inherited from interface jakarta.persistence.metamodel.Type

    getJavaType

    Methods inherited from interface org.hibernate.usertype.UserType

    getDefaultSqlLength, getDefaultSqlLength, getDefaultSqlPrecision, getDefaultSqlPrecision, getDefaultSqlScale, getDefaultSqlScale, getValueConverter, isComparable, nullSafeGet, nullSafeSet

    Methods inherited from interface org.hibernate.metamodel.mapping.ValueMapping

    treatAs
  • 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(tools.jackson.databind.ObjectMapper objectMapper)
    • JsonType

      public JsonType(ObjectMapperWrapper objectMapperWrapper)
    • JsonType

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

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

    • getName

      public String getName()