Announcement Announcement Module
No announcement yet.
Intermediate repository interface with generics Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Intermediate repository interface with generics

    I have a class NamedEntity, which has a name attribute. I'd like to search by this field using a findByName method. But not just on that class, but also all the subclasses, so I've build this:

    public class NamedEntity() {
    	String name;
    public class Book extends NamedEntity() {}
    public interface NameSearchableRepository<T extends NamedEntity> extends GraphRepository<T> {
        public T findByName(String name)
    public interface BookRepository extends NameSearchableRepository<Book> {}
    Here I have an intermediate repository interface NameSearchableRepository. I can now nicely do a BookRepository.findByName() and get a correctly typed Book back (rather than having to cast/project NamedEntity to Book). Also, I don't have to repeat the findByName method in all other subinterfaces of the intermediate interface.

    However, the generic portion in that intermediate interface seems to trouble the (Neo4j) implementation. My question is this: is this scenario generally supported by SDC?

    Edit: to be a bit more precise: the problem is with the generic return type on findByName, which returns null instead of the requested (and very much existing) entity. Using a collection as return type makes SDN fall over trying to detect the actual type parameter.
    Last edited by Johannes Mockenhaupt; May 31st, 2013, 01:28 AM.