I am using a subselect to simulate a view, the order by clause does not seem to be working correctly, did I do something wrong? Any help appreciated.
HQL:
=======================================================================
select r from ConformanceByPolicyReport r order by r.num desc
=======================================================================
SQL generated by Hibernate (It sorts the results as desired):
=======================================================================
select conformanc0_.ELEMENT_ID as ELEMENT1_, conformanc0_.SUBJECT_NAME as SUBJECT2_10_, conformanc0_.ELEMENT_NAME as ELEMENT3_10_, conformanc0_.RESULT_STATUS as RESULT4_10_, conformanc0_.NUM as NUM10_ from (
select element_id, subject_name, element_name, result_status, count(*) num
from test_results_tbl, policy_elements_tbl, element_subjects_tbl
where (result_policy_element_id = element_id) and (element_subject = subject_id)
group by element_id, subject_name, element_name, result_status
) conformanc0_ order by conformanc0_.NUM desc
=======================================================================
Mapping:
=======================================================================
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="">
<class name="ConformanceByPolicyReport" node="Row" mutable="false">
<subselect>
select element_id, subject_name, element_name, result_status, count(*) num
from test_results_tbl, policy_elements_tbl, element_subjects_tbl
where (result_policy_element_id = element_id) and (element_subject = subject_id)
group by element_id, subject_name, element_name, result_status
</subselect>
<cache usage="read-write" region="cache.ConformanceByPolicyReportCache"/>
<synchronize table="TEST_RESULTS_TBL"/>
<synchronize table="POLICY_ELEMENTS_TBL"/>
<synchronize table="ELEMENT_SUBJECTS_TBL"/>
<id name="elementId" column="ELEMENT_ID" type="java.lang.String" node="element_id">
<generator class="assigned"/>
</id>
<property name="subjectName" column="SUBJECT_NAME" type="java.lang.String" node="subject_name"/>
<property name="elementName" column="ELEMENT_NAME" type="java.lang.String" node="element_name"/>
<property name="resultStatus" column="RESULT_STATUS" type="java.lang.Integer" node="result_status"/>
<property name="num" column="NUM" type="java.lang.Integer" node="num"/>
</class>
</hibernate-mapping>
=======================================================================
Results (POJO entity mode): // I limited the output to just num & subject_name to shorten it up.
=======================================================================
>>>> Got 143 results...
... Result: ( num: 50, subjectName = General )
... Result: ( num: 50, subjectName = Content Model )
... Result: ( num: 50, subjectName = General )
... Result: ( num: 45, subjectName = Types )
... Result: ( num: 45, subjectName = Types )
... Result: ( num: 45, subjectName = General )
... Result: ( num: 45, subjectName = Types )
... Result: ( num: 45, subjectName = Types )
... Result: ( num: 45, subjectName = General )
... Result: ( num: 45, subjectName = Types )
... Result: ( num: 45, subjectName = Types )
... Result: ( num: 45, subjectName = Encoding )
... Result: ( num: 45, subjectName = General )
... Result: ( num: 45, subjectName = Content Model )
... Result: ( num: 45, subjectName = Content Model )
... Result: ( num: 45, subjectName = Types )
... Result: ( num: 45, subjectName = Content Model )
... Result: ( num: 45, subjectName = Namespace )
... Result: ( num: 45, subjectName = Content Model )
... Result: ( num: 45, subjectName = Types )
... Result: ( num: 45, subjectName = General )
... Result: ( num: 45, subjectName = Types )
... Result: ( num: 45, subjectName = Content Model )
... Result: ( num: 45, subjectName = Types )
... Result: ( num: 45, subjectName = General )
... Result: ( num: 45, subjectName = General )
... Result: ( num: 45, subjectName = Types )
... Result: ( num: 45, subjectName = General )
... Result: ( num: 45, subjectName = Style )
... Result: ( num: 45, subjectName = General )
... Result: ( num: 45, subjectName = General )
... Result: ( num: 45, subjectName = Namespace )
... Result: ( num: 45, subjectName = Types )
... Result: ( num: 45, subjectName = Types )
... Result: ( num: 45, subjectName = General )
... Result: ( num: 44, subjectName = General )
... Result: ( num: 36, subjectName = Content Model )
... Result: ( num: 36, subjectName = Types )
... Result: ( num: 36, subjectName = Content Model )
... Result: ( num: 36, subjectName = Content Model )
... Result: ( num: 36, subjectName = Types )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 27, subjectName = General )
... Result: ( num: 27, subjectName = General )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 27, subjectName = Style )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 27, subjectName = Style )
... Result: ( num: 18, subjectName = Style )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 18, subjectName = Content Model )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 27, subjectName = General )
... Result: ( num: 18, subjectName = Namespace )
... Result: ( num: 18, subjectName = Style )
... Result: ( num: 18, subjectName = Encoding )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 18, subjectName = Content Model )
... Result: ( num: 18, subjectName = Imports/Includes )
... Result: ( num: 27, subjectName = General )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 18, subjectName = Content Model )
... Result: ( num: 18, subjectName = Namespace )
... Result: ( num: 18, subjectName = Imports/Includes )
... Result: ( num: 18, subjectName = Style )
... Result: ( num: 18, subjectName = Imports/Includes )
... Result: ( num: 18, subjectName = Encoding )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 18, subjectName = Content Model )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 18, subjectName = Encoding )
... Result: ( num: 18, subjectName = Imports/Includes )
... Result: ( num: 18, subjectName = Content Model )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 18, subjectName = Style )
... Result: ( num: 18, subjectName = Content Model )
... Result: ( num: 18, subjectName = Imports/Includes )
... Result: ( num: 18, subjectName = Imports/Includes )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 18, subjectName = Imports/Includes )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 18, subjectName = Encoding )
... Result: ( num: 18, subjectName = Encoding )
... Result: ( num: 18, subjectName = Imports/Includes )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 18, subjectName = Style )
... Result: ( num: 18, subjectName = Style )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 18, subjectName = Content Model )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 18, subjectName = Namespace )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 18, subjectName = Content Model )
... Result: ( num: 18, subjectName = General )
... Result: ( num: 18, subjectName = Namespace )
... Result: ( num: 18, subjectName = Encoding )
... Result: ( num: 27, subjectName = Types )
... Result: ( num: 36, subjectName = Content Model )
... Result: ( num: 36, subjectName = Types )
... Result: ( num: 36, subjectName = Content Model )
... Result: ( num: 36, subjectName = Content Model )
... Result: ( num: 36, subjectName = Types )
... Result: ( num: 5, subjectName = N/A )
... Result: ( num: 5, subjectName = N/A )
... Result: ( num: 5, subjectName = Namespace )
... Result: ( num: 5, subjectName = N/A )
... Result: ( num: 5, subjectName = Namespace )
... Result: ( num: 5, subjectName = Encoding )
... Result: ( num: 5, subjectName = Content Model )
... Result: ( num: 5, subjectName = General )
... Result: ( num: 5, subjectName = N/A )
... Result: ( num: 5, subjectName = Encoding )
... Result: ( num: 5, subjectName = General )
... Result: ( num: 5, subjectName = Namespace )
... Result: ( num: 5, subjectName = N/A )
... Result: ( num: 5, subjectName = Namespace )
... Result: ( num: 5, subjectName = N/A )
... Result: ( num: 5, subjectName = Encoding )
... Result: ( num: 5, subjectName = N/A )
... Result: ( num: 5, subjectName = Content Model )
... Result: ( num: 5, subjectName = General )
... Result: ( num: 5, subjectName = N/A )
... Result: ( num: 5, subjectName = Security )
... Result: ( num: 5, subjectName = N/A )
... Result: ( num: 5, subjectName = Content Model )
... Result: ( num: 4, subjectName = N/A )
... Result: ( num: 44, subjectName = General )
... Result: ( num: 4, subjectName = N/A )
|