-->
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.  [ 3 posts ] 
Author Message
 Post subject: order by UserType
PostPosted: Mon Nov 05, 2007 1:53 pm 
Newbie

Joined: Mon Sep 17, 2007 7:04 pm
Posts: 3
Hi,

I've created a UserType for the replicationOperation property of one of my mapped classes (ReplicationAudit). The relevant part of the mapping file is shown below:

Code:
    <class name="ReplicationAudit" table="REPLICATION_AUDIT">          
        <property name="replicationOperation" column="REPLICATION_OPERATION_ID" type="com.example.replication.model.personalization.ReplicationOperationUserType" not-null="true" /> 
       
    </class>


The UserType has a name property, but when I try to order by this property I get an exception containing the following message

Quote:
could not resolve property: name of: com.example.replication.model.personalization.ReplicationAudit


I've tried writing the query in two ways:
Code:
               
                "from ReplicationAudit ra " +
                "where ra.id > :afterId " +
                "and ra.id <= :uptoId " +
                "order by ra.replicationOperation.name asc"

and:
Code:
       
                "from ReplicationAudit ra " +
                "inner join ra.replicationOperation as raOp " +
                "where ra.id > :afterId " +
                "and ra.id <= :uptoId " +               
                "order by raOp.name asc"


But the result is the same in both cases. From the error message, it seems like Hibernate is trying to order by ReplicationAudit.name, rather than ReplicationAudit.replicationOperation.name.

Thanks in Advance,
DM


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 05, 2007 6:28 pm 
Newbie

Joined: Wed Oct 31, 2007 5:36 pm
Posts: 13
You can have your ReplicationOperationUserType implement Comparable
and implement the compareTo method:

Code:
public int compareTo(ReplicationOperationUserType other) {
  return this.name.compareTo(other.name);
}



Then your queries can order by replicationOperation instead of replicationOperation.name


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 1:19 pm 
Newbie

Joined: Mon Sep 17, 2007 7:04 pm
Posts: 3
I did wonder if that would work......I'll try it out - thanks very much!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

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.