Ravi Parekh
Ravi Parekh

Reputation: 5594

hibernate inner join

i need inner join with

"select 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>

Upvotes: 1

Views: 4392

Answers (1)

ssedano
ssedano

Reputation: 8432

The inner join to a collection should be done like:

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 + "%'"

More on this topic at the manual

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

Upvotes: 2

Related Questions