I have been doing this for several hours and have not found anyone who would get this job. I want to save a BigDecimal object in Mongo, but Mongo does not support BigDecimal. I followed Spring docs here , but no luck.
From what I can tell, Spring doesn't introduce my custom converter classes in Mongo when it is written in db. Here is what I did:
My application context-services.xml ...
<mongo:mongo host="localhost" port="1234" /> <mongo:db-factory dbname="solar" mongo-ref="mongo"/> <mongo:mapping-converter> <mongo:custom-converters> <mongo:converter> <bean class="com.mine.BigDecimalReadConverter"/> </mongo:converter> <mongo:converter> <bean class="com.mine..BigDecimalWriteConverter"/> </mongo:converter> </mongo:custom-converters> </mongo:mapping-converter> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/> <bean id="mongoDbTest" class="com.mine.MongoDbTest"> <property name="mongoTemplate"> <ref local="mongoTemplate" /> </property> </bean>
The error I am getting is:
java.lang.IllegalArgumentException: Multiple constructors with arguments found in class java.math.BigDecimal! Annotate one with @PreferedConstructor explicitly to select it to be used in persistence operations. at org.springframework.data.mapping.PreferredConstructorDiscoverer.<init>(PreferredConstructorDiscoverer.java:81)
source share