Class JsonType
- 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
jsonbandjsoncolumn types - MySQL - for the
jsoncolumn type - SQL Server - for the
NVARCHARcolumn type storing JSON - Oracle - for the
JSONcolumn type if you're using Oracle 21c or theVARCHARcolumn type storing JSON if you're using an older Oracle version - H2 - for the
jsoncolumn 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 -
Field Summary
FieldsFields inherited from interface org.hibernate.usertype.DynamicParameterizedType
ACCESS_TYPE, ENTITY, IS_DYNAMIC, IS_PRIMARY_KEY, PARAMETER_TYPE, PROPERTY, RETURNED_CLASS, XPROPERTY -
Constructor Summary
ConstructorsConstructorDescriptionJsonType()JsonType(com.fasterxml.jackson.databind.ObjectMapper objectMapper) JsonType(JsonConfiguration configuration) JsonType(ObjectMapperWrapper objectMapperWrapper) JsonType(ObjectMapperWrapper objectMapperWrapper, Type javaType) JsonType(org.hibernate.type.spi.TypeBootstrapContext typeBootstrapContext) -
Method Summary
Methods inherited from class io.hypersistence.utils.hibernate.type.MutableDynamicParameterizedType
setParameterValuesMethods inherited from class io.hypersistence.utils.hibernate.type.MutableType
assemble, deepCopy, disassemble, disassemble, equals, forEachDisassembledJdbcValue, forEachJdbcType, getBindableJavaType, getConfiguration, getExpressibleJavaType, getJavaTypeDescriptor, getJdbcMapping, getJdbcTypeDescriptor, getMappedType, getSqlType, hashCode, isMutable, nullSafeGet, nullSafeSet, replace, returnedClassMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.hibernate.metamodel.mapping.BasicValuedMapping
addToCacheKey, getJdbcMapping, getJdbcTypeCount, getSingleJdbcMappingMethods inherited from interface org.hibernate.metamodel.mapping.Bindable
forEachDisassembledJdbcValue, forEachDisassembledJdbcValue, forEachDisassembledJdbcValue, forEachJdbcType, forEachJdbcValue, forEachJdbcValue, forEachJdbcValue, forEachJdbcValueMethods inherited from interface org.hibernate.metamodel.model.domain.DomainType
getSqmType, getTupleLengthMethods inherited from interface org.hibernate.query.sqm.SqmExpressible
getRelationalJavaType, getTypeName, isInstance, resolveExpressibleMethods inherited from interface org.hibernate.usertype.UserType
getDefaultSqlLength, getDefaultSqlPrecision, getDefaultSqlScale, getJdbcType, getValueConverterMethods inherited from interface org.hibernate.metamodel.mapping.ValueMapping
treatAs
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
JsonType
public JsonType() -
JsonType
-
JsonType
-
JsonType
public JsonType(org.hibernate.type.spi.TypeBootstrapContext typeBootstrapContext) -
JsonType
public JsonType(com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
JsonType
-
JsonType
-
JsonType
-
-
Method Details
-
getName
-