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.