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