I have a mongo collection that may contain three types of entities that I map to java types:
Collecti
Spring data uses the Repository-Declarations as entry-point when looking for Entity classes (it does not scan packages for entities directly).
So all you need to do is to declare an "unused" Repository-Interface for your sub-classes, just like you proposed as "unsafe" in your OP:
public interface NodeRepository extends MongoRepository {
// all of your repo methods go here
Node findById(String id);
Node findFirst100ByNodeType(String nodeType);
... etc.
}
public interface LeafType1Repository extends MongoRepository {
// leave empty
}
public interface LeafType2Repository extends MongoRepository {
// leave empty
}
You do not have to use the additional LeafTypeX repositories, you can stick with the NodeRepository for storing and looking up objects of type LeafType1 and LeafType2. But the declaration of the other two repositories is needed, so that LeafType1 and LeafType2 will be found as Entities when initial scanning takes place.
PS: This all assumes, of course, that you have @Document(collection= "nodes") annotations on your LeafType1 and LeafType2 classes