You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Caused by: org.springframework.data.mapping.MappingException: Ambiguous mapping! Annotation PrimaryKeyColumn configured on field customer and one of its accessor methods in class Key!
at org.springframework.data.mapping.model.AnnotationBasedPersistentProperty.validateAnnotation(AnnotationBasedPersistentProperty.java:154) ~[spring-data-commons-2.4.5.jar:2.4.5]
at org.springframework.data.mapping.model.AnnotationBasedPersistentProperty.lambda$populateAnnotationCache$7(AnnotationBasedPersistentProperty.java:126) ~[spring-data-commons-2.4.5.jar:2.4.5]
at java.base/java.util.Optional.ifPresent(Optional.java:178) ~[na:na]
at org.springframework.data.mapping.model.AnnotationBasedPersistentProperty.populateAnnotationCache(AnnotationBasedPersistentProperty.java:120) ~[spring-data-commons-2.4.5.jar:2.4.5]
at org.springframework.data.mapping.model.AnnotationBasedPersistentProperty.<init>(AnnotationBasedPersistentProperty.java:88) ~[spring-data-commons-2.4.5.jar:2.4.5]
at org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentProperty.<init>(BasicCassandraPersistentProperty.java:80) ~[spring-data-cassandra-3.1.5.jar:3.1.5]
at org.springframework.data.cassandra.core.mapping.CachingCassandraPersistentProperty.<init>(CachingCassandraPersistentProperty.java:40) ~[spring-data-cassandra-3.1.5.jar:3.1.5]
at org.springframework.data.cassandra.core.mapping.CassandraMappingContext.createPersistentProperty(CassandraMappingContext.java:403) ~[spring-data-cassandra-3.1.5.jar:3.1.5]
at org.springframework.data.cassandra.core.mapping.CassandraMappingContext.createPersistentProperty(CassandraMappingContext.java:60) ~[spring-data-cassandra-3.1.5.jar:3.1.5]
at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:543) ~[spring-data-commons-2.4.5.jar:2.4.5]
at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:521) ~[spring-data-commons-2.4.5.jar:2.4.5]
at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:708) ~[spring-core-5.3.4.jar:5.3.4]
at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:384) ~[spring-data-commons-2.4.5.jar:2.4.5]
at org.springframework.data.cassandra.core.mapping.CassandraMappingContext.addPersistentEntity(CassandraMappingContext.java:337) ~[spring-data-cassandra-3.1.5.jar:3.1.5]
at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:333) ~[spring-data-commons-2.4.5.jar:2.4.5]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.data.mapping.context.AbstractMappingContext.initialize(AbstractMappingContext.java:462) ~[spring-data-commons-2.4.5.jar:2.4.5]
at org.springframework.data.cassandra.core.mapping.CassandraMappingContext.initialize(CassandraMappingContext.java:117) ~[spring-data-cassandra-3.1.5.jar:3.1.5]
at org.springframework.data.mapping.context.AbstractMappingContext.afterPropertiesSet(AbstractMappingContext.java:454) ~[spring-data-commons-2.4.5.jar:2.4.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1845) ~[spring-beans-5.3.4.jar:5.3.4]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782) ~[spring-beans-5.3.4.jar:5.3.4]
... 74 common frames omitted
Changing just the Key class to a regular class works fine:
Thanks for report. The issue is caused because we compare a merged annotation with the declared annotation and Spring's merged annotations hydrate also aliases. Furthermore, Java records copy annotations to their accessors and therefore the annotation gets declared twice as of the bytecode. We can fix the issue easily in Spring Data Commons.
mp911de
changed the title
@PrimaryKeyClass annotation fails on java record types with an "Ambiguous mapping" exceptionAnnotationBasedPersistentProperty.validateAnnotation(…) compares declared annotations with merged annotations
May 5, 2021
We now validate declared annotations by pre-processing these through AnnotatedElementUtils to ensure a proper comparison. Previously, we compared annotation in their declared form (AnnotatedElement.getAnnotations()) with merged annotations which could fail due to aliasing effects of merged annotations.
Closes#2368.
We now validate declared annotations by pre-processing these through AnnotatedElementUtils to ensure a proper comparison. Previously, we compared annotation in their declared form (AnnotatedElement.getAnnotations()) with merged annotations which could fail due to aliasing effects of merged annotations.
Closes#2368.
We now validate declared annotations by pre-processing these through AnnotatedElementUtils to ensure a proper comparison. Previously, we compared annotation in their declared form (AnnotatedElement.getAnnotations()) with merged annotations which could fail due to aliasing effects of merged annotations.
Closes#2368.
Declaring @table on a record class works fine, but @PrimaryKeyClass does not.
For instance:
throws this exception:
Changing just the Key class to a regular class works fine:
The text was updated successfully, but these errors were encountered: