Candlejack
Candlejack

Reputation: 266

Error when inserting joda DateTime into MongoDB via Spring Data

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

Upvotes: 3

Views: 2289

Answers (2)

vivex
vivex

Reputation: 2515

Its a bug in Spring Data MongoDB, I was getting the same stackoverflow error while inserting JODA LocalTime to database, but when i switched to java LocalTime, it worked fine.

Upvotes: 1

Stefan Podkowinski
Stefan Podkowinski

Reputation: 5249

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?

Upvotes: 4

Related Questions