I have an @Entity Video having a one-to-many relation with a List<Tag> tags as one of its fields. I use the following @Repository using 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 Query is processed and considered valid by Spring, I tested the generated SQL vs my database locally and it returned 2 Tags. In my Code however, I receive the value Null when I call the method findMostViewedTags(100).
The Query lookup strategy is the default "CREATE_IF_NOT_FOUND".
- If there are no results found, should the method return an empty list or Null? My desired behavior is to receive an empty list.
- Why does the method call return
Nullinstead of aList<Tag>with size() 2?
maxTagsisn't used or that isn't the query you are actually executing.