As far as seeing the sql goes, if you have log4j or similar in your application, then you can define
Code:
<category name="org.hibernate.SQL" additivity="false">
<priority value="DEBUG"/>
<appender-ref ref="FILE"/>
</category>
and the sql should show up in your logging file (or console, or whatever your appender is).
As far as your hql goes, I am a new user as well, but the way we have been setting up our application is:
You should have a class DeviceReadings which has your attributes from DEVICE_READINGS. DeviceReadings could contain an set that will contain a collection of ErrorHistory objects.
Your DeviceReadings mapping file will then contain <property> definitions for each of the attributes from that table, and a <set> definition for the collection of ErrorHistory objects.
You will also have to map the ErrorHist table
Your hql can then simply be something like
Code:
<query name="findAllDeviceReadings">
<![CDATA[
from DeviceReading dr where dr.brandName = :bn and dr.serialNumber = :sn and dr.modelNumber = :mn ]]>
</query>
Roughly:
[code]
<hibernate-mapping ...
<class name="DeviceReadings" table="DEVICE_READINGS">
<id ....
<!-- Use your id generation methodology -->
</id>
<property name="brandName" column="BRAND_NAME" />
.
.
.
<set name="errorHistory" table="ERROR_HIST" >
<key column="DEVICE_READING_KEY" />
<one-to-many class="ErrorHistory" />
</set>
</class>
<class name="ErrorHistory" table="ERROR_HISTORY">
<id ....
<!-- Use your id generation methodology -->
</id>
<property name="attribte1" column="ATTR_1" />
<property name="attribte2" column="ATTR_2" />
.
.
.
</class>
<query name="findAllDeviceReadings">
<![CDATA[
from DeviceReading dr where dr.brandName = :bn and dr.serialNumber = :sn and dr.modelNumber = :mn ]]>
</query>
</hibernate-mapping>
Define your Java classes with matching names etc and then when you run the query you should get a DeviceReadings object(s) with an embedded Set of ErrorHistory objects relevant for each DeviceReadings.
Andrew