【问题标题】:hibernate inner join休眠内连接
【发布时间】:2011-05-09 09:42:10
【问题描述】:

我需要内部加入

"选择 rc.* from"

"from RateCode rc inner join rc.rateCodeParams rcCod where rc.rateCodeId = rcCod.id and rc.travelFrom <= '2011-05-09' and rc.travelTo >= '2011-05-13' and rc.active = 1" +
        " and rcCod.paramVal like '%" + roomId + "%'"

rateCodeParam.hbm

<class catalog="hermes" name="RateCodeParam" table="ratecodeparam">
    <id name="id" type="java.lang.Integer">
      <column name="id"/>
      <generator class="identity"/>
    </id>
    <property name="paramVal" type="string">
      <column length="45" name="paramVal"/>
    </property>
 <many-to-one class="RateCode" insert="false" name="rateCode" update="false">
      <column name="p_id"/>
    </many-to-one>
</class>

rateCode.hbm

<class catalog="hermes" name="RateCode" table="ratecodes">
    <id name="rateCodeId" type="java.lang.Integer">
      <column name="id"/>
      <generator class="native"/>
    </id>
<set cascade="all, delete-orphan" name="rateCodeParams" order-by="param">
      <key>
        <column name="p_id"/>
      </key>
      <one-to-many class="RateCodeParam"/>
</set>
</class>

【问题讨论】:

  • select rc from RateCode rc inner join rc.rateCodeParams rcCod where rc.rateCodeId = rcCod.id and rc.travelFrom = '2011-05 -13' and rc.active = 1" + " and rcCod.paramVal like '%" + roomId + "%'

标签: java hibernate hql


【解决方案1】:

集合的inner join 应该是这样的:

from RateCode rc inner join rc.rateCodeParams rcCod where rc.rateCodeId = rcCod.id and rc.travelFrom <= '2011-05-09' and rc.travelTo >= '2011-05-13' and rc.active = 1" +
            " and rcCod.paramVal like '%" + roomId + "%'"

有关此主题的更多信息,请参阅手册

[1]http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html

【讨论】:

  • 嗨,感谢您的帮助,还有一件事是我如何从上面得到“select rc.* from...”,我得到了 Object[2] -> RateCode(0),RateCodeParam(1)
  • 你想做什么,对不起,但我想我不明白这个问题。如果您确实从 RateCode 中选择 rc... 会返回什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-15
  • 2011-01-05
  • 2016-09-07
  • 1970-01-01
  • 1970-01-01
  • 2016-04-20
相关资源
最近更新 更多