java.lang.IllegalArgumentException: Target bean is not of type of the persistent entity!

Spring JIRA | Amy Aldredge | 6 months ago
  1. 0

    In {{BasicPersistentEntity.getPropertyAccessor(…), please change the message given to the assert to be more descriptive. Instead of: {code:java} Assert.isTrue(getType().isInstance(bean), "Target bean is not of type of the persistent entity!"); {code} use something like {code:java} Assert.isTrue(getType().isInstance(bean), "Target bean (" + bean.getClass().getName() + ") is not of type (" + getType().getName() +") of the persistent entity!"); {code} 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: {noformat} 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:?] {noformat}

    Spring JIRA | 6 months ago | Amy Aldredge
    java.lang.IllegalArgumentException: Target bean is not of type of the persistent entity!
  2. 0

    spring data rest: PATCH request with projection param

    Stack Overflow | 12 months ago | Ickbinet
    java.lang.IllegalArgumentException: Target bean is not of type of the persistent entity!
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Sprint-data-Cassandra Mapping of Map with User Defined Type fails with "not of type of the persistent entity"

    Stack Overflow | 6 hours ago | pfellwock
    java.lang.IllegalArgumentException: Target bean of type java.util.LinkedHashMap is not of type of the persistent entity (com.pfellwock.cassandra.type.App)!
  5. 0

    How to delete Serializable entity exposed with Spring data rest and spring data mongo

    Stack Overflow | 10 months ago | Gerald
    java.lang.IllegalArgumentException: Target bean is not of type of the persistent entity!
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.IllegalArgumentException

    Target bean is not of type of the persistent entity!

    at org.springframework.util.Assert.isTrue()
  2. Spring Core
    Assert.isTrue
    1. org.springframework.util.Assert.isTrue(Assert.java:68)[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    1 frame
  3. Spring Data Core
    BasicPersistentEntity.getPropertyAccessor
    1. org.springframework.data.mapping.model.BasicPersistentEntity.getPropertyAccessor(BasicPersistentEntity.java:394)[spring-data-commons-1.11.4.RELEASE.jar:?]
    1 frame
  4. Spring Data MongoDB - Core
    MappingMongoConverter$1.doWithPersistentProperty
    1. org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:253)[spring-data-mongodb-1.8.4.RELEASE.jar:?]
    2. org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:231)[spring-data-mongodb-1.8.4.RELEASE.jar:?]
    3. org.springframework.data.mongodb.core.convert.MappingMongoConverter.readValue(MappingMongoConverter.java:1186)[spring-data-mongodb-1.8.4.RELEASE.jar:?]
    4. org.springframework.data.mongodb.core.convert.MappingMongoConverter.access$200(MappingMongoConverter.java:78)[spring-data-mongodb-1.8.4.RELEASE.jar:?]
    5. org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:1134)[spring-data-mongodb-1.8.4.RELEASE.jar:?]
    6. org.springframework.data.mongodb.core.convert.MappingMongoConverter.getValueInternal(MappingMongoConverter.java:870)[spring-data-mongodb-1.8.4.RELEASE.jar:?]
    7. org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:283)[spring-data-mongodb-1.8.4.RELEASE.jar:?]
    8. org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:271)[spring-data-mongodb-1.8.4.RELEASE.jar:?]
    8 frames
  5. Spring Data Core
    BasicPersistentEntity.doWithProperties
    1. org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:309)[spring-data-commons-1.11.4.RELEASE.jar:?]
    1 frame
  6. Spring Data MongoDB - Core
    MongoTemplate$ReadDbObjectCallback.doWith
    1. org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:271)[spring-data-mongodb-1.8.4.RELEASE.jar:?]
    2. org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:231)[spring-data-mongodb-1.8.4.RELEASE.jar:?]
    3. org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:191)[spring-data-mongodb-1.8.4.RELEASE.jar:?]
    4. org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:187)[spring-data-mongodb-1.8.4.RELEASE.jar:?]
    5. org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:78)[spring-data-mongodb-1.8.4.RELEASE.jar:?]
    6. org.springframework.data.mongodb.core.MongoTemplate$ReadDbObjectCallback.doWith(MongoTemplate.java:2230)[spring-data-mongodb-1.8.4.RELEASE.jar:?]
    6 frames