Question

I have a MongoTemplate with custom mapping converters:

    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
        <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
        <constructor-arg name="mongoConverter" ref="mappingConverter"/>
    </bean>

    <mongo:mapping-converter id="mappingConverter" >
        <mongo:custom-converters>
            <mongo:converter>
                <bean class="foo.bar.flap.MyCustomTypeToStringConverter"/>
            </mongo:converter>
            <mongo:converter>
                <bean class="foo.bar.flap.MyOtherCustomTypeConverter"/>
            </mongo:converter>
        </mongo:custom-converters>
    </mongo:mapping-converter> 

This configuration seems to ignore JPA annotations such as @Id and @Transient.

According to this post from Oliver Gierke on the Spring forums, I need to use the MappingMongoConverter to enable this. However, I can't seem to figure out the right syntax for combining the MappingMongoConverter with the existing custom converters.

Can anyone point me to an example?

Was it helpful?

Solution

Not enough info.

Your <mongo:mapping-converter> is correct.

We don't see now an issue.

Note, Oliver made a comment for @Id and @Transient from org.springframework.data.annotation, not JPA.

Maybe that is a confuse for you?

Just change JPA annotation to Spring Data and you'll get it worked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top