@@ -238,7 +238,24 @@ public TypeInformation<?> getTypeUltimatelyReferredToBy(PersistentProperty<?> pr
238
238
*/
239
239
private @ Nullable PersistentEntity <?, ?> getEntityIdentifiedBy (TypeInformation <?> type ) {
240
240
241
+ Collection <PersistentEntity <?, ?>> entities = getPersistentEntities (type );
242
+
243
+ if (entities .size () > 1 ) {
244
+
245
+ String message = "Found multiple entities identified by " + type .getType () + ": " ;
246
+ message += entities .stream ().map (it -> it .getType ().getName ()).collect (Collectors .joining (", " ));
247
+ message += "; Introduce dedicated unique identifier types or explicitly define the target type in @Reference" ;
248
+
249
+ throw new IllegalStateException (message );
250
+ }
251
+
252
+ return entities .isEmpty () ? null : entities .iterator ().next ();
253
+ }
254
+
255
+ private Collection <PersistentEntity <?, ?>> getPersistentEntities (TypeInformation <?> type ) {
256
+
241
257
Collection <PersistentEntity <?, ?>> entities = new ArrayList <>();
258
+
242
259
for (MappingContext <?, ? extends PersistentProperty <?>> context : getMappingContexts ()) {
243
260
244
261
for (PersistentEntity <?, ? extends PersistentProperty <?>> persistentProperties : context
@@ -253,16 +270,7 @@ public TypeInformation<?> getTypeUltimatelyReferredToBy(PersistentProperty<?> pr
253
270
}
254
271
}
255
272
256
- if (entities .size () > 1 ) {
257
-
258
- String message = "Found multiple entities identified by " + type .getType () + ": " ;
259
- message += entities .stream ().map (it -> it .getType ().getName ()).collect (Collectors .joining (", " ));
260
- message += "; Introduce dedicated unique identifier types or explicitly define the target type in @Reference" ;
261
-
262
- throw new IllegalStateException (message );
263
- }
264
-
265
- return entities .isEmpty () ? null : entities .iterator ().next ();
273
+ return entities ;
266
274
}
267
275
268
276
private Collection <? extends MappingContext <?, ? extends PersistentProperty <?>>> getMappingContexts () {
0 commit comments