【发布时间】:2012-08-31 07:03:06
【问题描述】:
我正在尝试获取以下代码来显示我的查询结果。不幸的是,它不起作用。
@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>。
我想作为替代方案,我可以只返回一个对象列表。我试图在谷歌周围试图找出要搜索哪些关键字才能找到这样的结果。虽然理想情况下,如果它只返回 Map!
【问题讨论】:
-
为什么你认为Spring Data可以将
Object[]隐式转换为Map?它是否记录在某处? -
我能够在
10.4.1.2部分找到docs.jboss.org/hibernate/core/3.3/reference/en/html/…,但我仍然不明白为什么它无法处理Map<String, Integer>。我正在研究那个例子,试图让它为我工作。
标签: java spring-data-jpa