Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step from spring boot 2.1 and java 12 to spring boot 2.2 and java 13 (using spring data mongo), cannot save document with collections field using default value as Collections.emptySet(); [DATACMNS-1607] #2037

Closed
spring-projects-issues opened this issue Nov 5, 2019 · 10 comments
Assignees
Labels
in: repository type: bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Nov 5, 2019

smastika opened DATACMNS-1607 and commented

Caused by: java.lang.IllegalArgumentException: Target bean of type java.util.Collections$EmptySet is not of type of the persistent entity (se.qopla.mothership.model.Allergen)!: java.util.Collections$EmptySetCaused by: java.lang.IllegalArgumentException: Target bean of type java.util.Collections$EmptySet is not of type of the persistent entity (se.qopla.mothership.model.Allergen)!: java.util.Collections$EmptySet at org.springframework.util.Assert.instanceCheckFailed(Assert.java:696) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.util.Assert.isInstanceOf(Assert.java:615) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.data.mapping.model.BasicPersistentEntity.verifyBeanType(BasicPersistentEntity.java:551) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.mapping.model.BasicPersistentEntity.getPropertyAccessor(BasicPersistentEntity.java:453) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.mapping.PersistentPropertyAccessor.setProperty(PersistentPropertyAccessor.java:76) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.lambda$setDateProperty$2(MappingAuditableBeanWrapperFactory.java:243) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] at org.springframework.data.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.setDateProperty(MappingAuditableBeanWrapperFactory.java:243) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.setCreatedDate(MappingAuditableBeanWrapperFactory.java:189) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.auditing.AuditingHandler.lambda$touchDate$9(AuditingHandler.java:219) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at java.util.Optional.ifPresent(Optional.java:176) ~[?:?] at org.springframework.data.auditing.AuditingHandler.touchDate(AuditingHandler.java:219) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.auditing.AuditingHandler.lambda$touch$0(AuditingHandler.java:166) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at java.util.Optional.map(Optional.java:258) ~[?:?] at org.springframework.data.auditing.AuditingHandler.touch(AuditingHandler.java:163) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.auditing.AuditingHandler.markCreated(AuditingHandler.java:131) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.auditing.IsNewAwareAuditingHandler.markAudited(IsNewAwareAuditingHandler.java:83) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.mongodb.core.mapping.event.AuditingEntityCallback.onBeforeConvert(AuditingEntityCallback.java:54) ~[spring-data-mongodb-2.2.0.RELEASE.jar:2.2.0.RELEASE] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:567) ~[?:?] at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:279) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.data.mapping.callback.EntityCallbackDiscoverer.lambda$computeCallbackInvokerFunction$2(EntityCallbackDiscoverer.java:340) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.mapping.callback.DefaultEntityCallbacks$SimpleEntityCallbackInvoker.invokeCallback(DefaultEntityCallbacks.java:111) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.mapping.callback.DefaultEntityCallbacks.callback(DefaultEntityCallbacks.java:88) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.mongodb.core.MongoTemplate.maybeCallBeforeConvert(MongoTemplate.java:2371) ~[spring-data-mongodb-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:1284) ~[spring-data-mongodb-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:1226) ~[spring-data-mongodb-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.save(SimpleMongoRepository.java:84) ~[spring-data-mongodb-2.2.0.RELEASE.jar:2.2.0.RELEASE] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:567) ~[?:?] at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:371) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:204) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:657) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:621) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:605) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE] at com.sun.proxy.$Proxy122.save(Unknown Source) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:567) ~[?:?] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE] at com.sun.proxy.$Proxy122.save(Unknown Source) ~[?:?] at se.qopla.mothership.LoadTestData.run(LoadTestData.java:108) ~[classes/:?] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:784) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] ... 5 more


Issue Links:

  • DATACMNS-1609 Auditing metadata should not detect paths containing map or collection like segments
@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 5, 2019

smastika commented

@Document
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@ToString
@Builder
public class RefProduct extends BaseDocument {
 private String name;
 private String description;
 private double defaultPrice;
 private double vatRate;
 @Indexed
 private String companyId;
 @Indexed
 private String refProductCategoryId;
 private Modifications modifications;
 @Indexed
 private Integer articleNumber;
 private String imageUrl;
 private List<Ingredient> ingredients;

// THIS DEFAULT VALUE FAILS
 @Builder.Default
 private Set<Allergen> allergens = Collections.emptySet();

 
}

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 5, 2019

smastika commented

if creating a new instance of RefProduct with builder using default value for allergens and just calling repository.save(instance);  throws exception above. This worked earlier and no code has been changed except stepping versions of spring boot and java

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 8, 2019

Christoph Strobl commented

Looking at the stack trace the issue seems to have its origin in MappingMetadataAuditableBeanWrapper. So it is likely to be the same as DATACMNS-1609.

smastika does either Ingredient or Allergen define a property marked with @CreatedDate?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 8, 2019

smastika commented

Christoph Strobl

Yes, I should have pasted the BaseDocument class too.

public abstract class BaseDocument {

@Id
private String id;
@Indexed
@CreatedDate
private Instant createdAt;
@LastModifiedDate
private Instant updatedAt;
private boolean disabled;
private boolean deleted;

}

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 28, 2019

dkrasilov commented

I have the same issue on this class

@Document
data class Abcde(
        @Id
        var id: String? = null,
        var listOfA: MutableCollection<A> = mutableListOf()
) {
    @CreatedDate
    var createdAt: ZonedDateTime? = null
    @LastModifiedDate
    var updatedAt: ZonedDateTime? = null
    @CreatedBy
    var createdBy: String? = null
    @LastModifiedBy
    var lastModifiedBy: String? = null
}

With such StackTrace

java.lang.IllegalArgumentException: Target bean of type java.util.ArrayList is not of type of the persistent entity (org.abc.de.A)!: java.util.ArrayListjava.lang.IllegalArgumentException: Target bean of type java.util.ArrayList is not of type of the persistent entity (org.abc.de.A)!: java.util.ArrayList at org.springframework.util.Assert.instanceCheckFailed(Assert.java:696) at org.springframework.util.Assert.isInstanceOf(Assert.java:615) at org.springframework.data.mapping.model.BasicPersistentEntity.verifyBeanType(BasicPersistentEntity.java:551) at org.springframework.data.mapping.model.BasicPersistentEntity.getPropertyAccessor(BasicPersistentEntity.java:453) at org.springframework.data.mapping.PersistentPropertyAccessor.setProperty(PersistentPropertyAccessor.java:76) at org.springframework.data.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.lambda$setDateProperty$2(MappingAuditableBeanWrapperFactory.java:243) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at org.springframework.data.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.setDateProperty(MappingAuditableBeanWrapperFactory.java:243) at org.springframework.data.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.setCreatedDate(MappingAuditableBeanWrapperFactory.java:189) at org.springframework.data.auditing.AuditingHandler.lambda$touchDate$9(AuditingHandler.java:219) at java.base/java.util.Optional.ifPresent(Optional.java:183) at org.springframework.data.auditing.AuditingHandler.touchDate(AuditingHandler.java:219) at org.springframework.data.auditing.AuditingHandler.lambda$touch$0(AuditingHandler.java:166) at java.base/java.util.Optional.map(Optional.java:265) at org.springframework.data.auditing.AuditingHandler.touch(AuditingHandler.java:163) at org.springframework.data.auditing.AuditingHandler.markCreated(AuditingHandler.java:131) at org.springframework.data.auditing.IsNewAwareAuditingHandler.markAudited(IsNewAwareAuditingHandler.java:83) at org.springframework.data.mongodb.core.mapping.event.AuditingEntityCallback.onBeforeConvert(AuditingEntityCallback.java:54) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:279) at org.springframework.data.mapping.callback.EntityCallbackDiscoverer.lambda$computeCallbackInvokerFunction$2(EntityCallbackDiscoverer.java:340) at org.springframework.data.mapping.callback.DefaultEntityCallbacks$SimpleEntityCallbackInvoker.invokeCallback(DefaultEntityCallbacks.java:111) at org.springframework.data.mapping.callback.DefaultEntityCallbacks.callback(DefaultEntityCallbacks.java:88) at org.springframework.data.mongodb.core.MongoTemplate.maybeCallBeforeConvert(MongoTemplate.java:2371) at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:1284) at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:1226) at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.save(SimpleMongoRepository.java:84) at jdk.internal.reflect.GeneratedMethodAccessor73.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:371) at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:204) at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:657) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:621) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:605) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.data.repository.core.support.MethodInvocationValidator.invoke(MethodInvocationValidator.java:99) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) at com.sun.proxy.$Proxy150.save(Unknown Source) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) at com.sun.proxy.$Proxy150.save(Unknown Source)

 

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 28, 2019

Christoph Strobl commented

dkrasilov please upgrade the spring-data-commons dependency to Moore SR2 (2.2.2.RELEASE). A fix via DATACMNS-1609 is available there

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 28, 2019

smastika commented

Christoph Strobl this goes for me too right? :)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 28, 2019

Christoph Strobl commented

smastika sure! Sorry, I've not been following up on this one once we closed DATACMNS-1609

Please let us know if the upgrade worked for you so we can close hopefully close this ticket

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Dec 14, 2019

smastika commented

Sorry for late reply but I just tested upgrading to spring boot 2.2.2 which uses data commons 2.2.3 and it works fine. Thanks!

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Dec 16, 2019

Christoph Strobl commented

fixed via:  DATACMNS-1609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository type: bug
Projects
None yet
Development

No branches or pull requests

2 participants