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

Subclass Repository returns also Superclass objects

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Investigating
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.6.1 (Evans SR1)
    • Fix Version/s: None
    • Component/s: Core, Repository
    • Labels:

      Description

      Having two types of entities, that are mapped to two Java classes in the single MongoDB collection:

      @Document
      public class Superclass { ... }
      
      @Document(collection = "superclass")
      public class Subclass extends Superclass { ... }
      

      and two repositories for those entities:

      public interface SuperclassRepository extends MongoRepository<Superclass, String> {}
      public interface SubclassRepository extends MongoRepository<Subclass, String> {}
      

      MongoRepositories don't handle the inheritance of the entities correctly. While querying for all Subclass objects (e.g. SubclassRepository.findAll()) the result set contains Superclass objects, that are instantiated (or at least have been tried to be instantiated) with null values for fields that are part of the Subclass, but are not part of the Superclass.

      The expected result would be that SubclassRepository should return only Subclass objects, while SuperclassRepository should return Superclass and Subclass objects. It works this way in Spring Data JPA.

        Attachments

          Activity

            People

            Assignee:
            cstrobl Christoph Strobl
            Reporter:
            mrasinski Mateusz RasiƄski
            Last updater:
            Christoph Strobl
            Votes:
            4 Vote for this issue
            Watchers:
            7 Start watching this issue

              Dates

              Created:
              Updated: