Description
Mateusz Rasiński opened DATAMONGO-1142 and commented
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
Affects: 1.6.1 (Evans SR1)
Reference URL: http://stackoverflow.com/questions/28025710/spring-data-mongodb-repositories-dont-implement-inheritance-correctly
Referenced from: pull request #266
4 votes, 7 watchers