Skip to content

Commit

Permalink
HHH-11935 : Log a warning and update documentation that enabling "emp…
Browse files Browse the repository at this point in the history
…ty" composites is an experimental feature

(cherry picked from commit 407360d)
  • Loading branch information
gbadner committed Aug 18, 2017
1 parent 845f75c commit 5720cdd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
Expand Up @@ -239,6 +239,9 @@ Default to `false` if Bean Validation is present in the classpath and Hibernate

3+|Misc options
|`hibernate.create_empty_composites.enabled` |`true` or `false` (default value) | Enable instantiation of composite/embeddable objects when all of its attribute values are `null`. The default (and historical) behavior is that a `null` reference will be used to represent the composite when all of its attributes are `null`.

This is an experimental feature that has known issues. It should not be used in production until it is stabilized. See Hibernate Jira issue https://hibernate.atlassian.net/browse/HHH-11936[HHH-11936] for details.

|`hibernate.entity_dirtiness_strategy` | fully-qualified class name or an actual `CustomEntityDirtinessStrategy` instance | Setting to identify a `org.hibernate.CustomEntityDirtinessStrategy` to use.
|`hibernate.default_entity_mode` |`pojo` (default value) or `dynamic-map` |Default `EntityMode` for entity representation for all sessions opened from this `SessionFactory`, defaults to `pojo`.
|===================================================================================================================================================================================================================================
Expand Down
Expand Up @@ -1257,10 +1257,13 @@ public interface AvailableSettings {
*/
String PROCEDURE_NULL_PARAM_PASSING = "hibernate.proc.param_null_passing";

/*
* Enable instantiation of composite/embedded objects when all of its attribute values are {@code null}.
/**
* [EXPERIMENTAL] Enable instantiation of composite/embedded objects when all of its attribute values are {@code null}.
* The default (and historical) behavior is that a {@code null} reference will be used to represent the
* composite when all of its attributes are {@code null}
* <p/>
* This is an experimental feature that has known issues. It should not be used in production
* until it is stabilized. See Hibernate Jira issue HHH-11936 for details.
*
* @since 5.1
*/
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.hibernate.LockMode;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.cache.CacheException;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
import org.hibernate.engine.jndi.JndiException;
Expand Down Expand Up @@ -1749,4 +1750,16 @@ void cannotResolveNonNullableTransientDependencies(
@LogMessage(level = WARN)
@Message(value = "A ManagedEntity was associated with a stale PersistenceContext. A ManagedEntity may only be associated with one PersistenceContext at a time; %s", id = 480)
void stalePersistenceContextInEntityEntry(String msg);

@LogMessage(level = WARN)
@Message(
id = 483,
value = "An experimental feature has been enabled (" +
AvailableSettings.CREATE_EMPTY_COMPOSITES_ENABLED +
"=true) that instantiates empty composite/embedded " +
"objects when all of its attribute values are null. This feature has known issues and " +
"should not be used in production until it is stabilized. See Hibernate Jira " +
"issue HHH-11936 for details."
)
void emptyCompositesEnabled();
}
Expand Up @@ -67,6 +67,7 @@
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy;
import org.hibernate.cache.spi.access.RegionAccessStrategy;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.Settings;
import org.hibernate.context.internal.JTASessionContext;
Expand Down Expand Up @@ -112,6 +113,7 @@
import org.hibernate.internal.util.config.ConfigurationException;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.mapping.RootClass;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metadata.CollectionMetadata;
Expand Down Expand Up @@ -238,6 +240,9 @@ public SessionFactoryImpl(final MetadataImplementor metadata, SessionFactoryOpti

this.jdbcServices = this.serviceRegistry.getService( JdbcServices.class );
this.dialect = this.jdbcServices.getDialect();

logIfEmptyCompositesEnabled( this.properties );

this.cacheAccess = this.serviceRegistry.getService( CacheImplementor.class );
this.sqlFunctionRegistry = new SQLFunctionRegistry( getDialect(), options.getCustomSqlFunctionMap() );

Expand Down Expand Up @@ -1573,4 +1578,20 @@ static SessionFactoryImpl deserialize(ObjectInputStream ois) throws IOException,
final String name = isNamed ? ois.readUTF() : null;
return (SessionFactoryImpl) locateSessionFactoryOnDeserialization( uuid, name );
}

private void logIfEmptyCompositesEnabled(Properties props ) {
final boolean isEmptyCompositesEnabled = ConfigurationHelper.getBoolean(
AvailableSettings.CREATE_EMPTY_COMPOSITES_ENABLED,
props,
false
);
if ( isEmptyCompositesEnabled ) {
// It would be nice to do this logging in ComponentMetamodel, where
// AvailableSettings.CREATE_EMPTY_COMPOSITES_ENABLED is actually used.
// Unfortunately that would end up logging a message several times for
// each embeddable/composite. Doing it here will log the message only
// once.
LOG.emptyCompositesEnabled();
}
}
}

0 comments on commit 5720cdd

Please sign in to comment.