Announcement Announcement Module
Collapse
No announcement yet.
[Mongo] inheritance and multiple non-zero-argument-constructors Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Mongo] inheritance and multiple non-zero-argument-constructors

    I am currently doing inheritance in my mongo entity. Saving is fine, but loading it back gives me the exception of :
    Code:
    Exception in thread "main" java.lang.NullPointerException
    	at org.springframework.data.mongodb.core.convert.MappedConstructor.<init>(MappedConstructor.java:56)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:212)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:200)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readCollectionOrArray(MappingMongoConverter.java:747)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getValueInternal(MappingMongoConverter.java:703)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:230)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:220)
    	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:173)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:220)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:200)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getValueInternal(MappingMongoConverter.java:713)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:230)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:220)
    	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:173)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:220)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:200)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:164)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:73)
    	at org.springframework.data.mongodb.core.MongoTemplate$ReadDbObjectCallback.doWith(MongoTemplate.java:1693)
    	at org.springframework.data.mongodb.core.MongoTemplate.executeFindOneInternal(MongoTemplate.java:1405)
    	at org.springframework.data.mongodb.core.MongoTemplate.doFindOne(MongoTemplate.java:1224)
    	at org.springframework.data.mongodb.core.MongoTemplate.findById(MongoTemplate.java:483)
    Version being used :
    Code:
    <org.springframework.version>3.1.1.RELEASE</org.springframework.version>
    <spring.data.mongo.version>1.0.1.RELEASE</spring.data.mongo.version>
    Reading from the documentation :
    You can have a single non-zero argument constructor whose constructor argument names match top level field names of document, that constructor will be used. Otherewise the zero arg constructor will be used. if there is more than one non-zero argument constructor an exception will be thrown.
    I assume this is why i am getting the exceptions because :
    - In my case, both the parent class and the child class has a non-zero argument constructor, and both also have the empty constructor.
    - And when i tried not extending the parent class, and it gets loaded fine.

    Is there any workaround for this, or is it simply unsupported right now where parent-child classes have each own's non-zero-argument-constructor ?

  • #2
    Wooops, i found the culprit, and it was not about non-zero-constructor issues at all.

    The cause was one property of my entity (which is just one of my own made classes) has the constructor issue, which doesnt match the convention spring mongo uses.

    Now everything works great !

    Sorry for the confusion =)

    Comment

    Working...
    X