HHH-10837 Add new setting to disable/enable scanning for the static metamodel.
This commit is contained in:
parent
83eb8b0f76
commit
248d9cca14
|
@ -1491,4 +1491,12 @@ public interface AvailableSettings {
|
||||||
* The default behavior is to allow access unless the session is bootstrapped via JPA.
|
* The default behavior is to allow access unless the session is bootstrapped via JPA.
|
||||||
*/
|
*/
|
||||||
String ALLOW_JTA_TRANSACTION_ACCESS = "hibernate.jta.allowTransactionAccess";
|
String ALLOW_JTA_TRANSACTION_ACCESS = "hibernate.jta.allowTransactionAccess";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A setting to control whether Hibernate should scan for a static metamodel
|
||||||
|
* or not. The default is {@code true}, i.e. Hibernate scans for static metamodel.
|
||||||
|
* If you don't use a static metamodel in your project, then you can set this setting
|
||||||
|
* to {@code false} to speed up deployment of your project.
|
||||||
|
*/
|
||||||
|
String STATIC_METAMODEL_ENABLED = "hibernate.static_metamodel.enabled";
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import javax.persistence.metamodel.SingularAttribute;
|
||||||
import javax.persistence.metamodel.Type;
|
import javax.persistence.metamodel.Type;
|
||||||
|
|
||||||
import org.hibernate.annotations.common.AssertionFailure;
|
import org.hibernate.annotations.common.AssertionFailure;
|
||||||
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.internal.EntityManagerMessageLogger;
|
import org.hibernate.internal.EntityManagerMessageLogger;
|
||||||
import org.hibernate.internal.HEMLogging;
|
import org.hibernate.internal.HEMLogging;
|
||||||
|
@ -177,14 +178,23 @@ class MetadataContext {
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked"})
|
@SuppressWarnings({"unchecked"})
|
||||||
public void wrapUp() {
|
public void wrapUp() {
|
||||||
LOG.trace( "Wrapping up metadata context..." );
|
final boolean traceEnabled = LOG.isTraceEnabled();
|
||||||
|
if ( traceEnabled ) {
|
||||||
|
LOG.trace( "Wrapping up metadata context..." );
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean staticMetamodelEnabled = Boolean.parseBoolean(
|
||||||
|
sessionFactory.getProperties().getOrDefault(
|
||||||
|
AvailableSettings.STATIC_METAMODEL_ENABLED, "true" ).toString() );
|
||||||
|
|
||||||
//we need to process types from superclasses to subclasses
|
//we need to process types from superclasses to subclasses
|
||||||
for ( Object mapping : orderedMappings ) {
|
for ( Object mapping : orderedMappings ) {
|
||||||
if ( PersistentClass.class.isAssignableFrom( mapping.getClass() ) ) {
|
if ( PersistentClass.class.isAssignableFrom( mapping.getClass() ) ) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final PersistentClass safeMapping = (PersistentClass) mapping;
|
final PersistentClass safeMapping = (PersistentClass) mapping;
|
||||||
LOG.trace( "Starting entity [" + safeMapping.getEntityName() + "]" );
|
if ( traceEnabled ) {
|
||||||
|
LOG.trace( "Starting entity [" + safeMapping.getEntityName() + ']' );
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
final EntityTypeImpl<?> jpa2Mapping = entityTypesByPersistentClass.get( safeMapping );
|
final EntityTypeImpl<?> jpa2Mapping = entityTypesByPersistentClass.get( safeMapping );
|
||||||
applyIdMetadata( safeMapping, jpa2Mapping );
|
applyIdMetadata( safeMapping, jpa2Mapping );
|
||||||
|
@ -208,16 +218,22 @@ class MetadataContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jpa2Mapping.lock();
|
jpa2Mapping.lock();
|
||||||
populateStaticMetamodel( jpa2Mapping );
|
if ( staticMetamodelEnabled ) {
|
||||||
|
populateStaticMetamodel( jpa2Mapping );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
LOG.trace( "Completed entity [" + safeMapping.getEntityName() + "]" );
|
if ( traceEnabled ) {
|
||||||
|
LOG.trace( "Completed entity [" + safeMapping.getEntityName() + ']' );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( MappedSuperclass.class.isAssignableFrom( mapping.getClass() ) ) {
|
else if ( MappedSuperclass.class.isAssignableFrom( mapping.getClass() ) ) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final MappedSuperclass safeMapping = (MappedSuperclass) mapping;
|
final MappedSuperclass safeMapping = (MappedSuperclass) mapping;
|
||||||
LOG.trace( "Starting mapped superclass [" + safeMapping.getMappedClass().getName() + "]" );
|
if ( traceEnabled ) {
|
||||||
|
LOG.trace( "Starting mapped superclass [" + safeMapping.getMappedClass().getName() + ']' );
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
final MappedSuperclassTypeImpl<?> jpa2Mapping = mappedSuperclassByMappedSuperclassMapping.get(
|
final MappedSuperclassTypeImpl<?> jpa2Mapping = mappedSuperclassByMappedSuperclassMapping.get(
|
||||||
safeMapping
|
safeMapping
|
||||||
|
@ -237,10 +253,14 @@ class MetadataContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jpa2Mapping.lock();
|
jpa2Mapping.lock();
|
||||||
populateStaticMetamodel( jpa2Mapping );
|
if ( staticMetamodelEnabled ) {
|
||||||
|
populateStaticMetamodel( jpa2Mapping );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
LOG.trace( "Completed mapped superclass [" + safeMapping.getMappedClass().getName() + "]" );
|
if ( traceEnabled ) {
|
||||||
|
LOG.trace( "Completed mapped superclass [" + safeMapping.getMappedClass().getName() + ']' );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -248,8 +268,10 @@ class MetadataContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( EmbeddableTypeImpl embeddable : embeddables.values() ) {
|
if ( staticMetamodelEnabled ) {
|
||||||
populateStaticMetamodel( embeddable );
|
for ( EmbeddableTypeImpl embeddable : embeddables.values() ) {
|
||||||
|
populateStaticMetamodel( embeddable );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,7 +353,9 @@ class MetadataContext {
|
||||||
private <X> Set<SingularAttribute<? super X, ?>> buildIdClassAttributes(
|
private <X> Set<SingularAttribute<? super X, ?>> buildIdClassAttributes(
|
||||||
AbstractIdentifiableType<X> ownerType,
|
AbstractIdentifiableType<X> ownerType,
|
||||||
Iterator<Property> propertyIterator) {
|
Iterator<Property> propertyIterator) {
|
||||||
LOG.trace( "Building old-school composite identifier [" + ownerType.getJavaType().getName() + "]" );
|
if ( LOG.isTraceEnabled() ) {
|
||||||
|
LOG.trace( "Building old-school composite identifier [" + ownerType.getJavaType().getName() + ']' );
|
||||||
|
}
|
||||||
Set<SingularAttribute<? super X, ?>> attributes = new HashSet<SingularAttribute<? super X, ?>>();
|
Set<SingularAttribute<? super X, ?>> attributes = new HashSet<SingularAttribute<? super X, ?>>();
|
||||||
while ( propertyIterator.hasNext() ) {
|
while ( propertyIterator.hasNext() ) {
|
||||||
attributes.add( attributeFactory.buildIdAttribute( ownerType, propertyIterator.next() ) );
|
attributes.add( attributeFactory.buildIdAttribute( ownerType, propertyIterator.next() ) );
|
||||||
|
@ -345,7 +369,7 @@ class MetadataContext {
|
||||||
// should indicate MAP entity mode, skip...
|
// should indicate MAP entity mode, skip...
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String metamodelClassName = managedTypeClass.getName() + "_";
|
final String metamodelClassName = managedTypeClass.getName() + '_';
|
||||||
try {
|
try {
|
||||||
final Class metamodelClass = Class.forName( metamodelClassName, true, managedTypeClass.getClassLoader() );
|
final Class metamodelClass = Class.forName( metamodelClassName, true, managedTypeClass.getClassLoader() );
|
||||||
// we found the class; so populate it...
|
// we found the class; so populate it...
|
||||||
|
|
Loading…
Reference in New Issue