Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-1438

Annotation based auditing fails for annotation properties underneath collection valued subpath

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.2 M1 (Moore), 2.1.3 (Lovelace SR3)
    • Component/s: None
    • Labels:

      Description

      If I have the following class structure:

      abstract class AbstractModel {
       
        	@CreatedDate 
              private Instant created;
      	@CreatedBy 
              private String creator;
      	@LastModifiedDate 
              private Instant modified;
      	@LastModifiedBy 
              private String modifier;
      }
       
      class MyModel extends AbstractModel {
          List<MyModel> models;
      }
      @Document
      class MyDocument extends MyModel {
          
      }
      

      Then I receive the following error when storing data using Spring Data MongoDB repositories:

      java.lang.IllegalArgumentException: Target bean of type java.util.ArrayList is not of type of the persistent entity (MyModel)!: java.util.ArrayList
          at org.springframework.util.Assert.instanceCheckFailedAssert(Assert.java:655)
          at org.springframework.util.Assert.isInstanceOf(Assert.java:574)
          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.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.lambda$setProperty$2(MappingAuditableBeanWrapperFactory:243)
          at java.iterable.forEach(Iterable.java:75)
          at org.springframework.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.setDateProperty(MappingAuditableBeanWrapperFactory:243)
          at org.springframework.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.setLastModifiedDate(MappingAuditableBeanWrapperFactory:220)
          at java.util.Optional.ifPresent(Optional.java:159)
          at org.springframework.data.auditing.AuditingHandler.touchDate(AuditingHandler.java:220)
      

      This worked without issue in previous versions of Spring Data MongoDB (2.0.x)

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              shollander shollander
              Last updater:
              Joris Scharp
              Votes:
              3 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: