Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

Intermediate repository interface with generics

$
0
0
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?

Viewing all articles
Browse latest Browse all 297

Trending Articles