Hibernate version:
Hibernate 3.2.3
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="hibernate.Application"
table="application"
>
<id
name="applicationId"
type="java.lang.Long"
column="ApplicationID"
>
<generator class="native" />
</id>
<property
name="applicationName"
type="java.lang.String"
column="ApplicationName"
length="50"
/>
<set
name="processApplications"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="ApplicationID" />
</key>
<one-to-many
class="hibernate.ProcessApplication"
/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="hibernate.ProcessApplication"
table="process_application"
>
<composite-id class="hibernate.ProcessApplication$Id">
<key-property name="processid" column="processid"/>
<key-property name="applicationid" column="applicationid"/>
</composite-id>
<property
name="testfield"
type="java.lang.String"
column="testfield"
length="50"
/>
</class>
</hibernate-mapping>
I have 2 tables (application and process_application table) it's a 1-to-many relationship. I tried to extract data using the following
List l = s.createCriteria(Application.class)
.createCriteria("processApplications")
.addOrder(Order.asc("testfield")).list();
I'm able to get the data but when I print out the content of the object th testfield property is not sorted. But when I use the following code
List l = s.createSQLQuery(" select distinct * from application app,process_application process_app " +
" where " +
" app.applicationid=process_app.applicationid and " +
" app.applicationid=1 " +
" order by process_app.testfield ")
.addEntity(Application.class)
.addEntity(ProcessApplication.class)
.list();
it works, I was able to see the content of the testfield sorted, I don't prefer this method as it is returning array of objects, I would prefer to get the Application object and work my way through the object graph.
Any idea why the sort is working on the second code and not on the first code ?
Thanks
|