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

Provide more descriptive error message in BasicPersistentEntity.getPropertyAccessor(…)

    XMLWordPrintable

    Details

    • Sprint:
      Hopper SR2

      Description

      In {{BasicPersistentEntity.getPropertyAccessor(…), please change the message given to the assert to be more descriptive. Instead of:

      Assert.isTrue(getType().isInstance(bean), "Target bean is not of type of the persistent entity!");
      

      use something like

      Assert.isTrue(getType().isInstance(bean), "Target bean (" + bean.getClass().getName() + ")  is not of type (" + getType().getName() +") of the persistent entity!");
      

      I came across this message via Spring Data MongoDB. The root cause was a nested class in the Java model did not match what was in MongoDB, but it was outrageously time consuming to track down because the message gives no clue. Thanks for considering.

      Partial stack trace:

       java.lang.IllegalArgumentException: Target bean is not of type of the persistent entity!
              at org.springframework.util.Assert.isTrue(Assert.java:68) ~[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
              at org.springframework.data.mapping.model.BasicPersistentEntity.getPropertyAccessor(BasicPersistentEntity.java:394) ~[spring-data-commons-1.11.4.RELEASE.jar:?]
              at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:253) ~[spring-data-mongodb-1.8.4.RELEASE.jar:?]
              at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:231) ~[spring-data-mongodb-1.8.4.RELEASE.jar:?]
              at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readValue(MappingMongoConverter.java:1186) ~[spring-data-mongodb-1.8.4.RELEASE.jar:?]
              at org.springframework.data.mongodb.core.convert.MappingMongoConverter.access$200(MappingMongoConverter.java:78) ~[spring-data-mongodb-1.8.4.RELEASE.jar:?]
              at org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:1134) ~[spring-data-mongodb-1.8.4.RELEASE.jar:?]
              at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getValueInternal(MappingMongoConverter.java:870) ~[spring-data-mongodb-1.8.4.RELEASE.jar:?]
              at org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:283) ~[spring-data-mongodb-1.8.4.RELEASE.jar:?]
              at org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:271) ~[spring-data-mongodb-1.8.4.RELEASE.jar:?]
              at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:309) ~[spring-data-commons-1.11.4.RELEASE.jar:?]
              at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:271) ~[spring-data-mongodb-1.8.4.RELEASE.jar:?]
              at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:231) ~[spring-data-mongodb-1.8.4.RELEASE.jar:?]
              at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:191) ~[spring-data-mongodb-1.8.4.RELEASE.jar:?]
              at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:187) ~[spring-data-mongodb-1.8.4.RELEASE.jar:?]
              at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:78) ~[spring-data-mongodb-1.8.4.RELEASE.jar:?]
              at org.springframework.data.mongodb.core.MongoTemplate$ReadDbObjectCallback.doWith(MongoTemplate.java:2230) ~[spring-data-mongodb-1.8.4.RELEASE.jar:?]
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              amy Amy Aldredge
              Last updater:
              Christoph Strobl
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: