When I execute below query in SQL Query analyzer, the resultset order that I get are different than when I run it thro Hibernate.
Below is the SQL defined in mapping file.
<sql-query name="InsuredEntityAddl.selectInsuredEntityAddl">
SELECT InsuredEntityAddl.InsuredEntity_UID, InsuredEntityAddl.Ins_Ent_Ver_NBR, InsuredEntityAddl.InterestType_CDE, InsuredEntityAddl.InterestSeq_UID, InsuredEntityAddl.InsName_Type_CDE, InsuredEntityAddl.InsName_Seq_UID, InsuredEntityAddl.Insured_Other_NME, InsuredEntityAddl.Policy_NBR, InsuredEntityAddl.Certificate_NBR, InsuredEntityAddl.Policy_Version_NBR FROM InsuredEntityAddl INNER JOIN PolicyChange on InsuredEntityAddl.Policy_NBR = PolicyChange.Policy_NBR and InsuredEntityAddl.Certificate_NBR = PolicyChange.Certificate_NBR and InsuredEntityAddl.Policy_Version_NBR = PolicyChange.Policy_Version_NBR WHERE InsuredEntityAddl.Policy_NBR =:Policy_NBR AND InsuredEntityAddl.Certificate_NBR =0000 AND InsuredEntityAddl.InsuredEntity_UID =:InsuredEntity_UID AND InsuredEntityAddl.Ins_Ent_Ver_NBR =1 AND InsuredEntityAddl.InterestType_CDE = 'N' AND InsuredEntityAddl.InsName_Type_CDE IN ('L','S') AND InsuredEntityAddl.InterestSeq_UID =0 AND (InsuredEntityAddl.Policy_Status_CDE IN ('C','E','X') or (InsuredEntityAddl.Policy_Status_CDE = 'D' and PolicyChange.Change_Eff_DTE >'2006-06-01 00:00:00.0' and (PolicyChange.NVOEndorsement_NBR = 0 or PolicyChange.NVOEndorsement_NBR IS NULL))) ORDER BY InsuredEntityAddl.InsName_Type_CDE desc, InsuredEntityAddl.InsName_Seq_UID
</sql-query>
InsName_Seq_UID is a small int and it is possible to have duplicate values in both InsName_Type_CDE and
InsName_Seq_UID. So even though hibernate records are in different order than sql query analyzer, it is still sorted per above criterial. only difference is if 2 rows are with the same InsName_Seq_UID and InsName_Type_CDE, then their position in the output is different in Hibernate and SQL Query analyzer.
I'm using MS SQL Server 2000.
Kindly help me to resolve this issue if you know the solution..
Thx..
|