-->
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 in Named Queries...
PostPosted: Mon Dec 01, 2008 4:40 pm 
Newbie

Joined: Sun Jul 23, 2006 3:08 pm
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hi,
I am using Named Query. I trouble i am having is i am not able to make the Order By clause work. This is the code i am using...the query works and i am getting data but only thing is data is not getting sorted.


Hibernate version:3.0

Mapping documents:<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"C:/Hibernate/org/hibernate/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.test.hibernate.Emp" table="emp">
<id name="empId" type="int" column="emp_id" >
<generator class="assigned"/>
</id>
<property name="empName">
<column name="emp_name" />
</property>
<property name="deptId">
<column name="dept_id" />
</property>
</class>
<sql-query name="sortTest"> <return alias="empDept" class="com.test.hibernate.namedquery.EmpDeptDTO"/> <![CDATA[SELECT p.EMP_ID AS {empDept.empId}, p.EMP_NAME AS {empDept.empName}, p.DEPT_ID AS {empDept.deptId}, d.DEPT_NAME AS {empDept.deptName} FROM EMP p, DEPT d WHERE p.DEPT_ID = d.DEPT_ID order by :sortField ASC]]> </sql-query></hibernate-mapping>




Code between sessionFactory.openSession() and session.close():session = sessionFactory.openSession();
Query query = session.getNamedQuery("calendarAdmin");
query.setString( "sortField", "calendar.calendarId" );
List empList = query.list();

[b]Full stack trace of any exception that occurs:No Exception. Query works but the data is not getting sorted.


Name and version of the database you are using:Oracle 10g

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

Thanks,
Senthil.


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.