improve the documentation for stuff about AttributeConverters and mutability

This commit is contained in:
Gavin 2022-12-29 22:55:56 +01:00 committed by Gavin King
parent 8aba946e77
commit d6be936da3
5 changed files with 38 additions and 9 deletions

View File

@ -32,6 +32,10 @@ import static java.lang.annotation.ElementType.*;
* context does not need to keep track of its state. This may help reduce memory allocation.
* </li>
* </ul>
* <p>
* This annotation may also be used to mark a Java type handled by a JPA
* {@link jakarta.persistence.AttributeConverter} as immutable, circumventing the need to treat
* it as mutable.
*
* @author Emmanuel Bernard
*/

View File

@ -22,7 +22,9 @@ import org.hibernate.type.descriptor.java.spi.RegistryHelper;
import org.hibernate.type.descriptor.jdbc.JdbcType;
/**
* Standard implementation of JpaAttributeConverter
* Standard implementation of {@link JpaAttributeConverter}.
*
* @see AttributeConverterMutabilityPlanImpl
*
* @author Steve Ebersole
*/

View File

@ -7,19 +7,38 @@
package org.hibernate.type.descriptor.converter;
import java.io.Serializable;
import java.lang.reflect.Type;
import org.hibernate.SharedSessionContract;
import org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter;
import org.hibernate.type.descriptor.java.MutableMutabilityPlan;
import org.hibernate.type.spi.TypeConfiguration;
/**
* The standard approach for defining a MutabilityPlan for converted (AttributeConverter)
* values is to always assume that they are immutable to make sure that dirty checking,
* deep copying and second-level caching all work properly no matter what. That was work
* done under https://hibernate.atlassian.net/browse/HHH-10111
* The default {@link org.hibernate.type.descriptor.java.MutabilityPlan} for a
* {@linkplain jakarta.persistence.AttributeConverter converted value} assumes,
* in the absence of additional evidence, that the value is <em>mutable</em>, so
* that dirty checking, deep copying, and second-level caching all work correctly
* in the case where it really is mutable.
* <p>
* As an exception to this, Java primitive types and {@code enum}s are inferred
* to be <em>immutable</em>.
* <p>
* To explicitly mark a converted value is immutable and avoid the extra processing
* required for a mutable value, either:
* <ul>
* <li>mark the Java type of the attribute, the type passed to the converter, as
* {@link org.hibernate.annotations.Immutable @Immutable},
* <li>explicitly specify a {@code MutabilityPlan} using
* {@link org.hibernate.annotations.Mutability @Mutability}, or
* <li>explicitly specify its {@link org.hibernate.boot.model.JavaTypeDescriptor}
* using {@link org.hibernate.annotations.JavaType @JavaType}.
* </ul>
*
* However a series of approaches to tell Hibernate that the values are immutable were
* documented as part of https://hibernate.atlassian.net/browse/HHH-10127
* @see <a href="https://hibernate.atlassian.net/browse/HHH-10111">HHH-10111</a>
* @see <a href="https://hibernate.atlassian.net/browse/HHH-10127">HHH-10127</a>
*
* @see org.hibernate.type.descriptor.java.spi.RegistryHelper#determineMutabilityPlan(Type, TypeConfiguration)
*
* @author Steve Ebersole
*/

View File

@ -8,5 +8,7 @@
/**
* Support for handling JPA {@link jakarta.persistence.AttributeConverter}
* instances as part of the Hibernate {@link org.hibernate.type.Type} system.
*
* @see org.hibernate.type.descriptor.converter.AttributeConverterMutabilityPlanImpl
*/
package org.hibernate.type.descriptor.converter;

View File

@ -8,7 +8,9 @@
/**
* Contracts for reading and writing values to and from JDBC.
* <p>
* Used by implementations of
* {@link org.hibernate.type.descriptor.jdbc.JdbcType}
* Used by implementations of {@link org.hibernate.type.descriptor.jdbc.JdbcType}
*
* @see org.hibernate.type.descriptor.ValueBinder
* @see org.hibernate.type.descriptor.ValueExtractor
*/
package org.hibernate.type.descriptor;