Using the below code I am unable to get the results of my query. Whether I use Map<ContentType... or Map<String... I get the same error: javax.persistence.NonUniqueResultException: result returns more than one elements
It seems like JPA should be able to handle multiple rows in Repositories. I’ve looked around for other annotations that I might just be missing and am having a hard time coming up with results.
Any suggestions on what I should do to resolve this?
@Transactional
public interface ContentRepository extends JpaRepository<Content,Integer>{
....
@Query(nativeQuery=true, value="SELECT content_type, COUNT(*) AS myColumn FROM dbo.content GROUP BY content_type")
Map<ContentType, Integer> getContentCountByType();
}
It appears that the problem was that
Map<ContentType, Integer>does not have a promise of a unique index, so JPA doesn’t like mapping to it. By usingList<Map<ContentType, Integer>>instead, it works great!