In my .hbm.xml there are two queries. The first one retrieves number of records in the table:
<query name="Airframe.SearchCount"><![CDATA[
select
count(*)
from
AirframeBean as a inner join
a.manufacturer as m
where
m.name like :manufacturer and
a.description like :description and
((a.percentSize <= :sizeMax and
a.percentSize >= :sizeMin) or
a.percentSize is null) and
((a.wingSpanInches <= :spanMax and
a.wingSpanInches >= :spanMin) or
a.wingSpanInches is null) and
((a.recommendedAuwMinLbs <= :auwMax and
a.recommendedAuwMaxLbs >= :auwMin) or
a.recommendedAuwMaxLbs is null)
]]></query>
And the second one gets data page-by-page using offset and limit:
<query name="Airframe.SearchData"><![CDATA[
select
a
from
AirframeBean as a inner join
a.manufacturer as m
where
m.name like :manufacturer and
a.description like :description and
((a.percentSize <= :sizeMax and
a.percentSize >= :sizeMin) or
a.percentSize is null) and
((a.wingSpanInches <= :spanMax and
a.wingSpanInches >= :spanMin) or
a.wingSpanInches is null) and
((a.recommendedAuwMinLbs <= :auwMax and
a.recommendedAuwMaxLbs >= :auwMin) or
a.recommendedAuwMaxLbs is null)
]]></query>
The queries are almost identical. the only one difference is that the first starts with select count(*)
and the second one starts with select a
. Is there a way to avoid copy-pasting?
Update The main problem is that I need Hibernate to validate schema, mappings and HQL queries at startup.