【问题标题】:Hibernate : Resultset mapping in to Map<EntityTypeId,List<EntitiyIds>>Hibernate:结果集映射到 Map<EntityTypeId,List<EntitiyIds>>
【发布时间】:2015-09-30 06:43:44
【问题描述】:

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

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

我写了如下查询来获取数据。如何修改此查询以将其作为 entitiyIds 列表作为值和 entityTypeId 作为键返回。

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

【问题讨论】:

    标签: java hibernate hibernate-mapping resultset named-query


    【解决方案1】:

    类似下面的东西

    <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

    【讨论】:

    • 嘿 Ankur,我已经尝试过了,但它返回 List> 其中 key 为 0 或 1,列值映射到它。
    • 有什么方法可以使用named-sql-query获取Map>的结果?
    猜你喜欢
    • 1970-01-01
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    • 1970-01-01
    • 2019-11-27
    • 2020-05-09
    • 1970-01-01
    相关资源
    最近更新 更多