this is hbm.xml
Code:
<hibernate-mapping>
<class table="settled" name="com.sample.db.model.SettledTxnLog">
<id unsaved-value="null" name="id" type="long" column="id">
<generator class="native"/>
</id>
........
<property name="tid" length="20" column="tid"/>
<property name="mid" length="20" column="mid"/>
<property name="txnDateTime" type="timestamp"/>
.....
</class>
</hibernate-mapping>
<hibernate-mapping>
<class table="terminal" name="com.sample.db.model.Terminal">
<id unsaved-value="null" name="id" type="long" column="id">
<generator class="native"/>
</id>
<property name="tid" length="20" column="tid" not-null="true"/>
<property name="mid" length="20" column="mid" not-null="true"/>
<many-to-one name="bank"/>
.......
</class>
</hibernate-mapping>
<hibernate-mapping>
<class table="bank" name="com.sample.db.model.Bank">
<id name="id" type="long" column="id">
<generator class="native"/>
</id>
....
<property name="name" length="40" column="name"/>
.....
</class>
</hibernate-mapping>
this is my sample HQL :
Code:
select count(*) from
(
select settled.mid
from com.sample.db.model.SettledTxnLog settled,
com.sample.db.model.Terminal terminal, com.sample.db.model.Bank bank
where settled.mid = terminal.mid and settled.tid = terminal.tid and bank.id = terminal.bank.id
AND settled.txnDateTime >= :startDate AND settled.txnDateTime <= :endDate
AND bank = :bank group by settled.mid, settled.tid having count(settled.mid) <= :maxNumberTrans
)
as table