1
  <hibernate-mapping package="com.test.info">
     <class name="LevelInfo">
        <composite-id>
           <key-property column="ID" name="id"/>
        </composite-id>
        <property column="NAME" name="name"/>
        <property column="DESC" name="desc"/>       

        <bag name="details" cascade="all" order-by="ID" >
             <key column="ID"/>
             <one-to-many class="DeatilInfo"/>
             <loader query-ref="includedDetailsSql"/>
       </bag>
    </class>

    <sql-query name="includedDetailsSql" >
          <load-collection alias="details" role="LevelInfo.details"/>
          SELECT {details.*} FROM
          DETAILS_TEMP detail
              WHERE detail.ID = ?
          AND detail.CODE=:myParam
    </sql-query>

    </hibernate-mapping>

The problem is that I want to pass parameter i.e myParam for filtering the records in the collection loading sql. Hibernate has passed the foreign key ID in the above query but I could not find a way to pass any other parameter in this query dynamically.

Further I also want to sort collection elements on a field that can be set dynamically. So is there any way to set order by attribute value in bag mapping dynamically.

Ali Arslan
  • 1,027
  • 10
  • 24

0 Answers0