Skip to content

Commit 8395be4

Browse files
committed
HSEARCH-5018 Add a config property to disable root mapping annotation discovery
1 parent 444345b commit 8395be4

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

mapper/orm/src/main/java/org/hibernate/search/mapper/orm/cfg/HibernateOrmMapperSettings.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer;
1414
import org.hibernate.search.mapper.orm.schema.management.SchemaManagementStrategyName;
1515
import org.hibernate.search.mapper.orm.search.loading.EntityLoadingCacheLookupStrategy;
16+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.ProjectionConstructor;
17+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.SearchEntity;
18+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.processing.RootMapping;
1619
import org.hibernate.search.mapper.pojo.tenancy.TenantIdentifierConverter;
1720
import org.hibernate.search.mapper.pojo.tenancy.spi.StringTenantIdentifierConverter;
1821
import org.hibernate.search.mapper.pojo.work.IndexingPlanSynchronizationStrategy;
@@ -152,10 +155,34 @@ private HibernateOrmMapperSettings() {
152155
* or a string that can be parsed into a Boolean value.
153156
* <p>
154157
* Defaults to {@link Defaults#MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES}.
158+
*
159+
* @see org.hibernate.search.mapper.pojo.mapping.definition.annotation.AnnotationMappingConfigurationContext#buildMissingDiscoveredJandexIndexes(boolean)
155160
*/
156161
public static final String MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES =
157162
PREFIX + Radicals.MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES;
158163

164+
/**
165+
* When {@link #MAPPING_PROCESS_ANNOTATIONS annotation processing is enabled} (the default),
166+
* whether Hibernate Search should automatically discover annotated types
167+
* present in the Jandex index that are also annotated
168+
* with {@link RootMapping root mapping annotations}.
169+
* <p>
170+
* When enabled, if an annotation meta-annotated with {@link RootMapping}
171+
* is found in the Jandex index,
172+
* and a type annotated with that annotation (e.g. {@link SearchEntity} or {@link ProjectionConstructor}) is found in the Jandex index,
173+
* then that type will automatically be scanned for mapping annotations,
174+
* even if the type wasn't explicitly added.
175+
* <p>
176+
* Expects a Boolean value such as {@code true} or {@code false},
177+
* or a string that can be parsed into a Boolean value.
178+
* <p>
179+
* Defaults to {@link Defaults#MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS}.
180+
*
181+
* @see org.hibernate.search.mapper.pojo.mapping.definition.annotation.AnnotationMappingConfigurationContext#discoverAnnotatedTypesFromRootMappingAnnotations(boolean)
182+
*/
183+
public static final String MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS =
184+
PREFIX + Radicals.MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS;
185+
159186
/**
160187
* A configurer for the Hibernate Search mapping.
161188
* <p>
@@ -287,10 +314,13 @@ private Radicals() {
287314
AUTOMATIC_INDEXING_PREFIX + AutomaticIndexingRadicals.ENABLE_DIRTY_CHECK;
288315
public static final String QUERY_LOADING_CACHE_LOOKUP_STRATEGY = "query.loading.cache_lookup.strategy";
289316
public static final String QUERY_LOADING_FETCH_SIZE = "query.loading.fetch_size";
290-
public static final String MAPPING_PROCESS_ANNOTATIONS = "mapping.process_annotations";
317+
public static final String MAPPING_PREFIX = "mapping.";
318+
public static final String MAPPING_PROCESS_ANNOTATIONS = MAPPING_PREFIX + "process_annotations";
291319
public static final String MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES =
292-
"mapping.build_missing_discovered_jandex_indexes";
293-
public static final String MAPPING_CONFIGURER = "mapping.configurer";
320+
MAPPING_PREFIX + "build_missing_discovered_jandex_indexes";
321+
public static final String MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS =
322+
MAPPING_PREFIX + "discover_annotated_types_from_root_mapping_annotations";
323+
public static final String MAPPING_CONFIGURER = MAPPING_PREFIX + "configurer";
294324
public static final String SCHEMA_MANAGEMENT_STRATEGY = "schema_management.strategy";
295325
public static final String COORDINATION = "coordination";
296326
public static final String COORDINATION_PREFIX = COORDINATION + ".";
@@ -415,6 +445,7 @@ private Defaults() {
415445
public static final int QUERY_LOADING_FETCH_SIZE = 100;
416446
public static final boolean MAPPING_PROCESS_ANNOTATIONS = true;
417447
public static final boolean MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES = true;
448+
public static final boolean MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS = true;
418449
public static final SchemaManagementStrategyName SCHEMA_MANAGEMENT_STRATEGY =
419450
SchemaManagementStrategyName.CREATE_OR_VALIDATE;
420451
public static final BeanReference<CoordinationStrategy> COORDINATION_STRATEGY =

mapper/orm/src/main/java/org/hibernate/search/mapper/orm/mapping/impl/HibernateOrmMappingInitiator.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ public class HibernateOrmMappingInitiator extends AbstractPojoMappingInitiator<H
5858
.withDefault( HibernateOrmMapperSettings.Defaults.MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES )
5959
.build();
6060

61+
private static final ConfigurationProperty<Boolean> MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS =
62+
ConfigurationProperty.forKey(
63+
HibernateOrmMapperSettings.Radicals.MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS )
64+
.asBoolean()
65+
.withDefault(
66+
HibernateOrmMapperSettings.Defaults.MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS )
67+
.build();
68+
6169
private static final OptionalConfigurationProperty<
6270
List<BeanReference<? extends HibernateOrmSearchMappingConfigurer>>> MAPPING_CONFIGURER =
6371
ConfigurationProperty.forKey( HibernateOrmMapperSettings.Radicals.MAPPING_CONFIGURER )
@@ -138,7 +146,8 @@ public void configure(MappingBuildContext buildContext,
138146
boolean processAnnotations = MAPPING_PROCESS_ANNOTATIONS.get( propertySource );
139147
if ( processAnnotations ) {
140148
annotationMapping()
141-
.discoverAnnotatedTypesFromRootMappingAnnotations( true )
149+
.discoverAnnotatedTypesFromRootMappingAnnotations(
150+
MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS.get( propertySource ) )
142151
.discoverJandexIndexesFromAddedTypes( true )
143152
.buildMissingDiscoveredJandexIndexes(
144153
MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES.get( propertySource ) )

0 commit comments

Comments
 (0)