34
34
import java .util .function .Predicate ;
35
35
import java .util .stream .Collectors ;
36
36
37
+ import org .slf4j .Logger ;
38
+ import org .slf4j .LoggerFactory ;
37
39
import org .springframework .beans .BeanUtils ;
38
40
import org .springframework .beans .BeansException ;
39
41
import org .springframework .beans .factory .InitializingBean ;
40
42
import org .springframework .context .ApplicationContext ;
41
43
import org .springframework .context .ApplicationContextAware ;
42
44
import org .springframework .context .ApplicationEventPublisher ;
43
45
import org .springframework .context .ApplicationEventPublisherAware ;
46
+ import org .springframework .core .KotlinDetector ;
44
47
import org .springframework .data .mapping .MappingException ;
45
48
import org .springframework .data .mapping .PersistentEntity ;
46
49
import org .springframework .data .mapping .PersistentProperty ;
60
63
import org .springframework .data .util .TypeInformation ;
61
64
import org .springframework .lang .Nullable ;
62
65
import org .springframework .util .Assert ;
66
+ import org .springframework .util .ClassUtils ;
63
67
import org .springframework .util .ReflectionUtils ;
64
68
import org .springframework .util .ReflectionUtils .FieldCallback ;
65
69
import org .springframework .util .ReflectionUtils .FieldFilter ;
85
89
public abstract class AbstractMappingContext <E extends MutablePersistentEntity <?, P >, P extends PersistentProperty <P >>
86
90
implements MappingContext <E , P >, ApplicationEventPublisherAware , ApplicationContextAware , InitializingBean {
87
91
92
+ private static final Logger LOGGER = LoggerFactory .getLogger (MappingContext .class );
93
+
88
94
private final Optional <E > NONE = Optional .empty ();
89
95
private final Map <TypeInformation <?>, Optional <E >> persistentEntities = new HashMap <>();
90
96
private final PersistentPropertyAccessorFactory persistentPropertyAccessorFactory = new ClassGeneratingPropertyAccessorFactory ();
@@ -535,6 +541,10 @@ private void createAndRegisterProperty(Property input) {
535
541
return ;
536
542
}
537
543
544
+ if (isKotlinOverride (property , input )) {
545
+ return ;
546
+ }
547
+
538
548
entity .addPersistentProperty (property );
539
549
540
550
if (property .isAssociation ()) {
@@ -547,6 +557,38 @@ private void createAndRegisterProperty(Property input) {
547
557
548
558
property .getPersistentEntityTypes ().forEach (AbstractMappingContext .this ::addPersistentEntity );
549
559
}
560
+
561
+ private boolean isKotlinOverride (P property , Property input ) {
562
+
563
+ if (!KotlinDetector .isKotlinPresent () || !input .getField ().isPresent ()) {
564
+ return false ;
565
+ }
566
+
567
+ Field field = input .getField ().get ();
568
+ if (!KotlinDetector .isKotlinType (field .getDeclaringClass ())) {
569
+ return false ;
570
+ }
571
+
572
+ for (P existingProperty : entity ) {
573
+
574
+ if (!property .getName ().equals (existingProperty .getName ())) {
575
+ continue ;
576
+ }
577
+
578
+ if (field .getDeclaringClass () != entity .getType ()
579
+ && ClassUtils .isAssignable (field .getDeclaringClass (), entity .getType ())) {
580
+
581
+ if (LOGGER .isTraceEnabled ()) {
582
+ LOGGER .trace (String .format ("Skipping '%s.%s' property declaration shadowed by '%s %s' in '%s'. " ,
583
+ field .getDeclaringClass ().getName (), property .getName (), property .getType ().getSimpleName (),
584
+ property .getName (), entity .getType ().getSimpleName ()));
585
+ }
586
+ return true ;
587
+ }
588
+ }
589
+
590
+ return false ;
591
+ }
550
592
}
551
593
552
594
/**
0 commit comments