Error when inserting joda DateTime into MongoDB via Spring Data

java, jodatime, mongodb, spring, spring-data

Solution

The StackOverflowError sounds like a bug you should file if its not from your code. Have you tried to use a custom converter to work around this problem?

Problem

today I encountered the following problem. When ever I add a joda DateTime field to one of my domain classes I cannot save any objects of this class into my MongoDB anymore. After a while a StackOverflowError is thrown, this it seems there is some kind of loop. As soon as I remove the field everything works fine again. I tried java mongo driver 2.9.3 and 2.10.0. Data binding takes place via Spring-Data-Mongo 1.1.1.RELEASE. Mongo version is 2.2.1. To persist the object I use MongoTemplate#save. ``` User user = new User("user"); mongoTemplate.save(user, "users"); ``` The User class looks like this (stripped down for simplicity): ``` public final class User { private final String suid; private DateTime datetime = DateTime.now(); public User(String suid) { this.suid = suid; } public String getSuid() { return suid; } } ``` I tried several web searches but could not find anyone else having this problem or any hints how to handle joda time. Any hints on this would be greatly appreciated. Thanks, Chris

Original source