1

以下のコードを取得してクエリ結果を表示しようとしています。残念ながら、それは機能していません。

@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);

objectsObject[]変数デバッガーになります。使用するように指示した に従わない理由がわかりません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!

4

1 に答える 1

1

クエリ結果を次のようにキャストObject[]し、次のドキュメントを使用します:http ://docs.jboss.org/hibernate/core/3.3/reference/en/html/objectstate.html#objectstate-querying-executing at section10.4.1.2は、私の問題を解決しました

于 2012-09-06T13:47:33.897 に答える