如何使用Hibernate< subselect&gt ;: [英] How to use Hibernate <subselect>:

查看:148
本文介绍了如何使用Hibernate< subselect&gt ;:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是休眠的新手。我需要了解以下问题:
$ b

(1)hibernate映射中的子选择是什么?



(2) )如何在hbm文件中映射subselect?



(3)如果我使用subselect检索值,那么如何在java Action类中获取检索值。 b $ b

解决方案


  1. 根据 section 5.1.3 subselect 元素用于定义一个基于任意本地查询结果的只读/不可变实体。
  2. 在同一个源代码中,只需使用 subselect

  3. code> class 元素而不是 table 属性中,然后使用查询中定义的列名作为属性映射中的列名称。 (第5.1.3节逐字逐句如下)

     < class name =总结> 
    < subselect>
    从项目
    中选择item.name,max(bid.amount),count(*)
    加入bid.item_id = item.id $ b $ group by item.name
    < / subselect>
    < synchronize table =item/>
    < synchronize table =bid/>
    < id name =name/>
    ...
    < / class>


  4. 使用中的查询中的列创建映射后,子查询元素,您应该可以像访问任何其他实体一样访问属性。



i am new to hibernate. i need to understand the following questions :

(1) What is subselect in hibernate mapping?

(2) How to map subselect in hbm file?

(3) If i retrieve values using subselect then how to get the retrieved values in java Action class.

解决方案

  1. Based on the description given in section 5.1.3, the subselect element is used to define a read-only/immutable entity which is based on the results of an arbitrary native query.
  2. From the same source, one simply uses subselect within a class element instead of the table attribute and then uses the column names defined in the query as column names in the property mapping. (the following is taken verbatim from section 5.1.3)

    <class name="Summary">
      <subselect>
        select item.name, max(bid.amount), count(*)
        from item
        join bid on bid.item_id = item.id
        group by item.name
      </subselect>
      <synchronize table="item"/>
      <synchronize table="bid"/>
      <id name="name"/>
      ...
    </class>
    

  3. After you create a mapping using columns from the query in the subselect element, you should be able to access the properties just as you would for any other entity.

这篇关于如何使用Hibernate&lt; subselect&gt ;:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆