Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 952
Candlejack Avatar asked Jul 07 '26 06:07

Candlejack


2 Answers

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?

like image 54
Stefan Podkowinski Avatar answered Jul 09 '26 18:07

Stefan Podkowinski


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.

like image 33
vivex Avatar answered Jul 09 '26 18:07

vivex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!