1
我试图让下面的代码显示我的查询结果。不幸的是它不工作。JPA数据仓库结果丢失其数据类型
@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
!
为什么你认为春节数据可以隐式转换'[对象]''到Map'?它是否记录在某处? – axtavt
我可以在10.4.1.2节找到http://docs.jboss.org/hibernate/core/3.3/reference/en/html/objectstate.html#objectstate-querying-executing,但我仍然不'不明白为什么它不能处理Map'。我正在努力尝试让它为我工作。 –
Webnet