-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Order by clause not working correctly when usng a subselect?
PostPosted: Tue May 31, 2005 4:37 pm 
Newbie

Joined: Wed May 18, 2005 4:26 pm
Posts: 6
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 )


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.