-->
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.  [ 6 posts ] 
Author Message
 Post subject: Using "order by" with multiple joins, multiple sor
PostPosted: Sat May 03, 2008 6:58 pm 
Beginner
Beginner

Joined: Sun Oct 14, 2007 7:29 pm
Posts: 23
Hello,

I have the following HQL query text with multiple joins and several order criteria:

Code:
select usrprof from Usrprofiles as usrprof, Compmsgs, Usrmsgs left join fetch usrprof.compdatas as comps left join fetch usrprof.usrmsgses umsgs left join fetch comps.compmsgses compmsgs where (usrprof.username='johndoe' and compmsgs.viewed=false and umsgs.viewed=false) order by comps.companyname asc, compmsgs.logdate desc, umsgs.logDate desc


For some reason, I cannot get the last sort/order criteria (
Code:
umsgs.logDate desc
to sort properly. Instead, it is coming back in ascending order, the default. However, when I look at the query output from Hibernate, I see that this criteria is being included:

Code:
[5/3/08 17:43:19:188 CDT] 0000008d SystemOut     O Hibernate:
    select
        usrprofile0_.UID as UID164_0_,
        compdata4_.COMPANYID as COMPANYID134_1_,
        compmsgses6_.MSGNUM as MSGNUM137_2_,
        usrmsgses5_.USRMSGSID as USRMSGSID163_3_,
        usrprofile0_.CONTACTID as CONTACTID164_0_,
        usrprofile0_.ROLE as ROLE164_0_,
        usrprofile0_.FIRSTNAME as FIRSTNAME164_0_,
        usrprofile0_.LASTNAME as LASTNAME164_0_,
        usrprofile0_.DATECREATED as DATECREA6_164_0_,
        usrprofile0_.USERNAME as USERNAME164_0_,
        usrprofile0_.PASSWORD as PASSWORD164_0_,
        usrprofile0_.DESC as DESC164_0_,
        usrprofile0_.EMAIL as EMAIL164_0_,
        usrprofile0_.FIRST_CH_Q as FIRST11_164_0_,
        usrprofile0_.FIRST_CH_A as FIRST12_164_0_,
        usrprofile0_.SEC_CH_Q as SEC13_164_0_,
        usrprofile0_.SEC_CH_A as SEC14_164_0_,
        usrprofile0_.THIRD_CH_Q as THIRD15_164_0_,
        usrprofile0_.THIRD_CH_A as THIRD16_164_0_,
        usrprofile0_.ACTIVE as ACTIVE164_0_,
        usrprofile0_.EMAIL_SIGNATURE as EMAIL18_164_0_,
        usrprofile0_.EMAIL_ALERTS_OK as EMAIL19_164_0_,
        usrprofile0_.LAST_UPDATE as LAST20_164_0_,
        compdata4_.CONTACTID as CONTACTID134_1_,
        compdata4_.COMPANYNAME as COMPANYN3_134_1_,
        compdata4_.REM_BAL as REM4_134_1_,
        compdata4_.ACCESSCODE as ACCESSCODE134_1_,
        compdatas3_.UID as UID0__,
        compdatas3_.COMPANYID as COMPANYID0__,
        compmsgses6_.MSGTYPENUM as MSGTYPENUM137_2_,
        compmsgses6_.COMPANYID as COMPANYID137_2_,
        compmsgses6_.MSG as MSG137_2_,
        compmsgses6_.LOGDATE as LOGDATE137_2_,
        compmsgses6_.VIEWED as VIEWED137_2_,
        compmsgses6_.TIME_READ as TIME7_137_2_,
        compmsgses6_.TIME_VIEWED as TIME8_137_2_,
        compmsgses6_.SENT_BY as SENT9_137_2_,
        compmsgses6_.COMPANYID as COMPANYID1__,
        compmsgses6_.MSGNUM as MSGNUM1__,
        usrmsgses5_.MSGTYPENUM as MSGTYPENUM163_3_,
        usrmsgses5_.UID as UID163_3_,
        usrmsgses5_.MSG as MSG163_3_,
        usrmsgses5_.LOG_DATE as LOG5_163_3_,
        usrmsgses5_.VIEWED as VIEWED163_3_,
        usrmsgses5_.TIME_VIEWED as TIME7_163_3_,
        usrmsgses5_.SENT_BY as SENT8_163_3_,
        usrmsgses5_.UID as UID2__,
        usrmsgses5_.USRMSGSID as USRMSGSID2__
    from
        faweb.USRPROFILES usrprofile0_
    left outer join
        faweb.USRPROFILES_X_COMPDATA compdatas3_
            on usrprofile0_.UID=compdatas3_.UID
    left outer join
        FAWEB.COMPDATA compdata4_
            on compdatas3_.COMPANYID=compdata4_.COMPANYID
    left outer join
        faweb.COMPMSGS compmsgses6_
            on compdata4_.COMPANYID=compmsgses6_.COMPANYID
    left outer join
        faweb.USRMSGS usrmsgses5_
            on usrprofile0_.UID=usrmsgses5_.UID,
        faweb.COMPMSGS compmsgs1_,
        faweb.USRMSGS usrmsgs2_
    where
        usrprofile0_.USERNAME='johndoe'
        and compmsgses6_.VIEWED='F'
        and usrmsgses5_.VIEWED='F'
    order by
        compdata4_.COMPANYNAME asc,
        compmsgses6_.LOGDATE desc,
        usrmsgses5_.LOG_DATE desc



Any ideas why my "usrmsgs.logdate" criteria is not working?

Thanks.

-Matt


Top
 Profile  
 
 Post subject: suggestions
PostPosted: Sun May 04, 2008 3:21 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
Well, obviously, if Hibernate relays this to the server, then the problem is not Hibernate, correct? :-) try isolating the problem: run test queries that order the USRMSGS table by LOG_DATE and see what happens.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 9:08 am 
Beginner
Beginner

Joined: Sun Oct 14, 2007 7:29 pm
Posts: 23
Actually, since this is not the actual SQL sent to the server, then it can be Hibernate. I do not know how to output/capture the actual SQL sent to the server, but this is not it.

-Matt


Top
 Profile  
 
 Post subject: server-side sql
PostPosted: Mon May 05, 2008 9:11 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
1. Is this the output of show_sql=true?
2. what dbms are you using? (including version number)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 2:02 pm 
Beginner
Beginner

Joined: Sun Oct 14, 2007 7:29 pm
Posts: 23
Quote:
1. Is this the output of show_sql=true?


Yes, it is the output of show_sql=true


Quote:
2. what dbms are you using? (including version number)

Using DB2 UDB V8.2.


Thanks.

-Matt


Top
 Profile  
 
 Post subject: enable tracing
PostPosted: Tue May 06, 2008 2:54 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
Why do you think that this is not the proper SQL?
When you try to manually execute this query against your db2, what is the outcome?
Still, if you're not certain that this is the actual query sent to the db, enable db2 tracing and pls post the actual query afterwards:
http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.admin.doc/doc/r0002027.htm


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

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.