I have a @Entity Videoone-to-many relationship with a List<Tag> tagsas one of its fields. I use the following @Repositoryusing Spring Data to get the most popular tags:
@Repository
public interface TagRepository extends CrudRepository<Tag, Integer>{
@Query("SELECT t FROM Tag t WHERE (SELECT SUM(v.views) FROM Video v WHERE t MEMBER OF v.tags) > 0")
public List<Tag> findMostViewedTags(int maxTags);
}
The request is processed and considered valid using Spring, I tested the generated SQL version and my database locally, and it returned 2 tags. However, in my code, I get Null when I call the findMostViewedTags (100) method.
The default query search strategy is "CREATE_IF_NOT_FOUND".
- If no results are found, should the method return an empty list or Null? My desire is to get an empty list.
- Why does the method call return
Nullinstead of List<Tag>with size () 2?
source
share