diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/NaturalIdCacheKey.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/NaturalIdCacheKey.java index 28437ec4ba..b5f7e5a462 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/NaturalIdCacheKey.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/spi/NaturalIdCacheKey.java @@ -47,6 +47,7 @@ public class NaturalIdCacheKey implements Serializable { private final String entityName; private final String tenantId; private final int hashCode; + // "transient" is important here -- NaturalIdCacheKey needs to be Serializable private transient ValueHolder toString; /** diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/ValueHolder.java b/hibernate-core/src/main/java/org/hibernate/internal/util/ValueHolder.java index 3570bb2020..d17dc0be52 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/ValueHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/ValueHolder.java @@ -26,6 +26,8 @@ package org.hibernate.internal.util; /** * Represents a "final" value that is initialized either {@link #ValueHolder(Object) up front} or once at some point * {@link #ValueHolder(ValueHolder.DeferredInitializer) after} declaration. + * + * Note: If a Serializable class has a {@link ValueHolder} property, that property should be declared transient! * * @author Steve Ebersole */ diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java index bf6baa9786..758c6ab288 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java @@ -86,8 +86,8 @@ public class MetadataImpl implements MetadataImplementor, Serializable { private final ServiceRegistry serviceRegistry; private final Options options; - private final ValueHolder classLoaderService; - private final ValueHolder persisterClassResolverService; + private final transient ValueHolder classLoaderService; + private final transient ValueHolder persisterClassResolverService; private TypeResolver typeResolver = new TypeResolver();