Announcement Announcement Module
Collapse
No announcement yet.
Intermediate repository interface with generics Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    Code:
    public class NamedEntity() {
    	String name;
    }
    
    public class Book extends NamedEntity() {}
    Code:
    @NoRepositoryBean
    public interface NameSearchableRepository<T extends NamedEntity> extends GraphRepository<T> {
        public T findByName(String name)
    }
    Code:
    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.
Working...
X