-->
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: Multiple table sort question
PostPosted: Sat Oct 20, 2007 11:05 am 
Newbie

Joined: Sat Oct 20, 2007 10:57 am
Posts: 1
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


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.