java - hibernate : Resultset mapping in to Map<EntityTypeId, 列表 <EntitiyIds>>

标签 java hibernate hibernate-mapping resultset named-query

我们有一个包含如下数据的表

id  entity_type_id  entity_id
1          1          1234
2          1          2356
3          1          7896
4          1          4321
5          2          1234
6          2          9876
7          2          5289
8          2          4568

And I wrote query as follow to get data. How can I modify this query to return it as list of entitiyIds as value and entityTypeId as key.

<query name="getAllEntities">
<![CDATA[
    SELECT e.entity_type_id, e.entity_id from entity as e
]]>
</query>

最佳答案

类似下面的内容

<query name="getAllEntities">
<![CDATA[
    SELECT new Map(e.entity_type_id as et_id, e.entity_id as e_id) from entity as e
]]>
</query>

引用this了解更多详情

关于java - hibernate : Resultset mapping in to Map<EntityTypeId, 列表 <EntitiyIds>>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32859491/

相关文章:

java - 如何在字符串数组中查找最大的字符串

spring - 在 JPA/hibernate 和 spring 中使用 joda time

hibernate - hibernate 查询转义(来自Grails的GORM)-再次

java - PGpoint Hibernate(反)序列化异常

java - 错误代码 : Why is this dangerous?

java - 默认情况下使用 zk 展开第一组并折叠剩余组

grails - 在Grails 3.x中使用JPA注释进行映射

java - Spring 4.3.0.RELEASE + Hibernate 5.2.0.Final - MySQL 上的 GeneratedValue

java - 为什么 IntelliJ IDEA 会发出此文件 javadoc 悬空的警告?

java - 如何使用 Hibernate\HQL 返回 Map<Key, Value>