Uploaded image for project: 'Spring Data MongoDB'
  1. Spring Data MongoDB
  2. DATAMONGO-1445

@Id annotated attribute of type BigInteger does not work with query methods



      I have a simple model, made up by three classes: Author, Book and Movie. Both Book and Movie have an author field.

      Here's the Author.

      @Document(collection = "authors")
      public class Author {
          private ObjectId id;
          private String firstName;
          private String lastName;

      Here's the Book. @Id is a BigInteger.

      @Document(collection = "books")
      public class Book {
          @Id private BigInteger id;
          @DBRef(lazy = true) private Author author;

      Here's the Movie. @Id is a String.

      @Document(collection = "movies")
      public class Movie {
          private String id;

      Here are the two repositories.

      public interface BookRepository extends PagingAndSortingRepository<Book, BigInteger> {
          public Book findByIsbn(String isbn);
          List<Book> findByAuthor(Author author);
          Book findByIdAndAuthor(BigInteger id, Author authorJohn);
          Book findById(BigInteger id);
      public interface MovieRepository extends CrudRepository<Movie, String> {
          Movie findByIdAndAuthor(String movieId, Author author);

      Now, the method Book#findByIdAndAuthor() fails. If you check the logs, it seems also pretty clear why.

      MovieRepository#findByIdAndAuthor() prints that. Notes that "_id" is contrained with an "$oid".

      2016-06-03 18:29:14 [main] DEBUG o.s.data.mongodb.core.MongoTemplate - findOne using query: { "_id" : { "$oid" : "5751b05ac2c9f73cde7f1800"} , "author" : { "_id" : { "$oid" : "5751b05ac2c9f73cde7f17ff"} , "firstName" : "Pasolini"}} in db.collection: tutorial.movies

      While BookRepository#findByIdAndAuthor() prints that. "_id" is not correctly queried with an "$oid".

      2016-06-03 18:30:09 [main] DEBUG o.s.data.mongodb.core.MongoTemplate - findOne using query: { "_id" : "27023952671160688784893370221" , "author" : { "$ref" : "authors" , "$id" : { "$oid" : "5751b091c2c9ea16c8115f6b"}}} in db.collection: tutorial.books




            • Assignee:
              olivergierke Oliver Drotbohm
              escher75 Daniele Demichelis
              Last updater:
              Oliver Drotbohm
            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: