以下のコードを取得してクエリ結果を表示しようとしています。残念ながら、それは機能していません。
@Transactional
public interface ContentRepository extends JpaRepository<Content,Integer>{
@Query(nativeQuery=true, value="SELECT content_type, COUNT(*) FROM dbo.content WHERE status_id = :statusId GROUP BY content_type")
List<Map<String, Integer>> getContentCountByType(@Param("statusId")Short statusId);
私のサービス層では...
@Service
public class ContentService {
@Transactional
public Map<ContentType, Integer> getContentCountByType() {
List<Map<String, Integer>> rawContentCount = contentRepository.getContentCountByType(Status.DRAFT);
Map<ContentType, Integer> contentCount = new HashMap<ContentType, Integer>();
Map<String, Integer> objects = rawContentCount.get(0);
objects
Object[]
変数デバッガーになります。使用するように指示した に従わない理由がわかりませんMap<String, Integer>
。
I was thinking as an alternative I could just return a list of objects. I'm trying to Google around trying to figure out what keywords to search for to find such a result. Though ideally I'd like to avoid having to create an object just for this query result if it would just return Map
!