Announcement Announcement Module
Collapse
No announcement yet.
PersistenceConstructor argument variable name doesn't match instance variable name Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PersistenceConstructor argument variable name doesn't match instance variable name

    I'm trying to persist the following object with spring-data-mongodb version 1.1.1.RELEASE:

    Code:
    @Document
    public static class TestObject {
        
        private final int m_property;
        
        @PersistenceConstructor
        public TestObject(int a_property) {
            m_property = a_property;
        }
        
        public int property() {
            return m_property;
        }
        
    }
    I get a MappingException when I try to read the object back from the database:

    No property a_property found on entity class com.recorder.TestRecorder$TestObject to bind constructor parameter to!

    The naming convention my group uses requires argument variable names to be prefaced by "a_" and instance variable names to be prefaced by "m_". It seems like spring-data-mongodb is making the assumption that the constructor argument variable names must match the object instance variable names.

    Why doesn't spring-data-mongodb use the constructor argument to instance variable mapping that I define within the constructor? Is there another way to define this mapping such that spring-data-mongodb will properly construct my object, or is my only option to break the naming convention?

    Code:
    Exception in thread "main" org.springframework.data.mapping.model.MappingException: No property a_property found on entity class com.recorder.TestRecorder$TestObject to bind constructor parameter to!
    	at org.springframework.data.mapping.model.PersistentEntityParameterValueProvider.getParameterValue(PersistentEntityParameterValueProvider.java:90)
    	at org.springframework.data.convert.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:70)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:229)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:209)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:173)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:169)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:72)
    	at org.springframework.data.mongodb.core.MongoTemplate$ReadDbObjectCallback.doWith(MongoTemplate.java:1820)
    	at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1542)
    	at org.springframework.data.mongodb.core.MongoTemplate.findAll(MongoTemplate.java:1064)
    	at com.recorder.TestRecorder.main(TestRecorder.java:43)
    Last edited by ben.baumgold; Dec 11th, 2012, 10:11 PM.

  • #2
    Already answered on StackOverflow. Please try to avoid cross posts. Thanks!

    Comment

    Working...
    X