HHH-7803 Added ENABLE_AUTO_INDEX_MEMBER_TYPES setting & disabled.
Corrected many test failures
This commit is contained in:
parent
248bda5958
commit
8e9ea2aaec
|
@ -713,4 +713,13 @@ public interface AvailableSettings {
|
|||
* do not attempt to create unique constraints on a schema update
|
||||
*/
|
||||
public static final String UNIQUE_CONSTRAINT_SCHEMA_UPDATE_STRATEGY = "hibernate.schema_update.unique_constraint_strategy";
|
||||
|
||||
/**
|
||||
* If enabled, an entity's member field types and method return types will automatically be indexed. This allows,
|
||||
* for example, auto-discovery of @Embeddables without explicitly listing them in the annotated classes. This
|
||||
* setting will also check classes identified by certain annotations (such as @Target). JPA requires these classes
|
||||
* to be identified in the annotated classes, however legacy Hibernate behavior was to allow it. Due to the
|
||||
* performance hit, disabled by default.
|
||||
*/
|
||||
public static final String ENABLE_AUTO_INDEX_MEMBER_TYPES = "hibernate.enable_auto_index_member_types";
|
||||
}
|
||||
|
|
|
@ -564,13 +564,17 @@ public class MetadataSources {
|
|||
}
|
||||
|
||||
public IndexView buildJandexView() {
|
||||
return buildJandexView( false );
|
||||
}
|
||||
|
||||
public IndexView buildJandexView(boolean autoIndexMemberTypes) {
|
||||
// create a jandex index from the annotated classes
|
||||
|
||||
Indexer indexer = new Indexer();
|
||||
|
||||
Set<Class<?>> processedClasses = new HashSet<Class<?>>();
|
||||
for ( Class<?> clazz : getAnnotatedClasses() ) {
|
||||
indexClass( clazz, indexer, processedClasses );
|
||||
indexClass( clazz, indexer, processedClasses, autoIndexMemberTypes );
|
||||
}
|
||||
|
||||
for ( String className : getAnnotatedClassNames() ) {
|
||||
|
@ -585,7 +589,7 @@ public class MetadataSources {
|
|||
return wrapJandexView( indexer.complete() );
|
||||
}
|
||||
|
||||
private void indexClass(Class clazz, Indexer indexer, Set<Class<?>> processedClasses) {
|
||||
private void indexClass(Class clazz, Indexer indexer, Set<Class<?>> processedClasses, boolean autoIndexMemberTypes) {
|
||||
if ( clazz == null || clazz == Object.class
|
||||
|| processedClasses.contains( clazz ) ) {
|
||||
return;
|
||||
|
@ -600,9 +604,15 @@ public class MetadataSources {
|
|||
// necessary to add all annotated classes. Entities would be enough. Mapped superclasses would be
|
||||
// discovered while processing the annotations. To keep this behavior we index all classes in the
|
||||
// hierarchy (see also HHH-7484)
|
||||
indexClass( clazz.getSuperclass(), indexer, processedClasses );
|
||||
indexClass( clazz.getSuperclass(), indexer, processedClasses, autoIndexMemberTypes );
|
||||
|
||||
// For backward compatibility, don't require @Embeddable
|
||||
// Similarly, index any inner class.
|
||||
for ( Class innerClass : clazz.getDeclaredClasses() ) {
|
||||
indexClass( innerClass, indexer, processedClasses, autoIndexMemberTypes );
|
||||
}
|
||||
|
||||
if ( autoIndexMemberTypes ) {
|
||||
// If autoIndexMemberTypes, don't require @Embeddable
|
||||
// classes to be explicitly identified.
|
||||
// Automatically find them by checking the fields' types.
|
||||
for ( Class<?> fieldType : ReflectHelper.getMemberTypes( clazz ) ) {
|
||||
|
@ -613,7 +623,7 @@ public class MetadataSources {
|
|||
fieldType );
|
||||
if ( !fieldIndex.getAnnotations(
|
||||
JPADotNames.EMBEDDABLE ).isEmpty() ) {
|
||||
indexClass( fieldType, indexer, processedClasses );
|
||||
indexClass( fieldType, indexer, processedClasses, autoIndexMemberTypes );
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
// do nothing
|
||||
|
@ -628,7 +638,8 @@ public class MetadataSources {
|
|||
.toString();
|
||||
Class<?> targetClass = serviceRegistry.getService(
|
||||
ClassLoaderService.class ).classForName( targetClassName );
|
||||
indexClass(targetClass, indexer, processedClasses );
|
||||
indexClass(targetClass, indexer, processedClasses, autoIndexMemberTypes );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,11 +45,14 @@ import org.hibernate.annotations.common.util.StringHelper;
|
|||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.spi.CacheRegionDefinition;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.NamingStrategy;
|
||||
import org.hibernate.cfg.ObjectNameNormalizer;
|
||||
import org.hibernate.cfg.annotations.NamedEntityGraphDefinition;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.ResultSetMappingDefinition;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.config.spi.StandardConverters;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.spi.FilterDefinition;
|
||||
import org.hibernate.engine.spi.NamedQueryDefinition;
|
||||
|
@ -175,9 +178,11 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
};
|
||||
|
||||
// todo : cache the built index if no inputs have changed (look at gradle-style hashing for up-to-date checking)
|
||||
boolean autoIndexMemberTypes = serviceRegistry.getService( ConfigurationService.class ).getSetting(
|
||||
AvailableSettings.ENABLE_AUTO_INDEX_MEMBER_TYPES, StandardConverters.BOOLEAN, false );
|
||||
final IndexView jandexView = options.getJandexView() != null
|
||||
? metadataSources.wrapJandexView( options.getJandexView() )
|
||||
: metadataSources.buildJandexView();
|
||||
: metadataSources.buildJandexView( autoIndexMemberTypes );
|
||||
Collection<AnnotationInstance> tables = jandexView.getAnnotations( JPADotNames.TABLE );
|
||||
final MetadataSourceProcessor[] metadataSourceProcessors;
|
||||
if ( options.getMetadataSourceProcessingOrder() == MetadataSourceProcessingOrder.HBM_FIRST ) {
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
*/
|
||||
package org.hibernate.loader;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Connection;
|
||||
|
@ -33,6 +37,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Embeddable;
|
||||
|
@ -44,8 +49,6 @@ import javax.persistence.FetchType;
|
|||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.engine.spi.LoadQueryInfluencers;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
|
@ -61,15 +64,10 @@ import org.hibernate.loader.spi.LoadQueryAliasResolutionContext;
|
|||
import org.hibernate.loader.spi.NamedParameterContext;
|
||||
import org.hibernate.loader.spi.NoOpLoadPlanAdvisor;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.test.component.cascading.toone.PersonalInfo;
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.junit4.ExtraAssertions;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
|
@ -78,7 +76,8 @@ public class EncapsulatedCompositeAttributeResultSetProcessorTest extends BaseCo
|
|||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Person.class, Customer.class };
|
||||
return new Class[] { Person.class, Customer.class, Address.class, AddressType.class, Customer.class,
|
||||
Investment.class, MonetaryAmount.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -73,7 +73,7 @@ public class EncapsulatedCompositeIdResultSetProcessorTest extends BaseCoreFunct
|
|||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Parent.class, CardField.class, Card.class };
|
||||
return new Class[] { Parent.class, CardField.class, Card.class, ParentPK.class, CardFieldPK.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -127,6 +127,7 @@ public class JoinedSubclassTest extends BaseCoreFunctionalTestCase {
|
|||
AmericaCupClass.class,
|
||||
Country.class,
|
||||
Vegetable.class,
|
||||
VegetablePk.class,
|
||||
Carrot.class,
|
||||
Tomato.class
|
||||
};
|
||||
|
|
|
@ -28,7 +28,6 @@ import static org.junit.Assert.assertNotNull;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -276,7 +275,11 @@ public class CollectionElementTest extends BaseCoreFunctionalTestCase {
|
|||
Boy.class,
|
||||
Country.class,
|
||||
TestCourse.class,
|
||||
Matrix.class
|
||||
Matrix.class,
|
||||
LocalizedString.class,
|
||||
Toy.class,
|
||||
CountryAttitude.class,
|
||||
Brand.class
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,7 +127,9 @@ public class OrderByTest extends BaseCoreFunctionalTestCase {
|
|||
return new Class[] {
|
||||
Products.class,
|
||||
Widgets.class,
|
||||
BugSystem.class
|
||||
BugSystem.class,
|
||||
Bug.class,
|
||||
Person.class
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import static junit.framework.Assert.assertEquals;
|
|||
public class TestBasicOps extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Query.class };
|
||||
return new Class[] { Query.class, Location.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.junit.Test;
|
|||
public class ElementCollectionSortingTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Person.class };
|
||||
return new Class[] { Person.class, Address.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -540,7 +540,11 @@ public class EmbeddedTest extends BaseCoreFunctionalTestCase {
|
|||
InternetFavorites.class,
|
||||
FixedLeg.class,
|
||||
FloatLeg.class,
|
||||
Swap.class
|
||||
Swap.class,
|
||||
RegionalArticlePk.class,
|
||||
LegalStructure.class,
|
||||
Summary.class,
|
||||
URLFavorite.class
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ import static org.junit.Assert.assertEquals;
|
|||
public class EmbeddableWithMany2OneTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Person.class, Country.class };
|
||||
return new Class[] { Person.class, Country.class, Address.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -266,6 +266,7 @@ public class JoinTest extends BaseCoreFunctionalTestCase {
|
|||
Death.class,
|
||||
Cat.class,
|
||||
Dog.class,
|
||||
DogPk.class,
|
||||
A.class,
|
||||
B.class,
|
||||
C.class,
|
||||
|
|
|
@ -331,7 +331,9 @@ public class ManyToManyComplexTest
|
|||
Employee.class,
|
||||
Contractor.class,
|
||||
PhoneNumber.class,
|
||||
ProgramManager.class
|
||||
ProgramManager.class,
|
||||
ContactInfo.class,
|
||||
JobInfo.class
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -470,7 +470,8 @@ public class QueryAndSQLTest extends BaseCoreFunctionalTestCase {
|
|||
Captain.class,
|
||||
Chaos.class,
|
||||
CasimirParticle.class,
|
||||
AllTables.class
|
||||
AllTables.class,
|
||||
Dimensions.class
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public class ComponentJoinsTest extends BaseCoreFunctionalTestCase {
|
|||
return new Class[] {
|
||||
Person.class,
|
||||
Component.class,
|
||||
Component.Emb.Stuff.class };
|
||||
Name.class};
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -40,7 +40,7 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|||
public class DoesNotWorkTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {DoesNotWork.class};
|
||||
return new Class[] { DoesNotWork.class, DoesNotWorkPk.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue