-->
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.  [ 4 posts ] 
Author Message
 Post subject: Ordering a query using an ordered map attribute
PostPosted: Fri Sep 12, 2003 4:29 pm 
Newbie

Joined: Fri Sep 12, 2003 4:01 pm
Posts: 19
Here's the situation. I have Documents and Authors, with a many-to-many
relationship. However, the ordering of the authors of a document must be
preserved, so this is implemented via an intermediate DocumentAuthor
class, with many-to-one relationships to the other two classes.

The DocumentAuthor class also has an integer attribute that records the
position of the associated author in the list of authors of the associated
document. I then define the Document -> DocumentAuthor association as
an ordered map.

Now I want to query for documents, ordered by the names of the first
authors. In other words, the usual way one would sort a bibliography.

I tried this:

select d from Document as d
order by d.documentAuthors[0].author.lastName

But it gets a syntax error (net.sf.hibernate.QueryException: Incorrect query syntax).

A similar query

select d from Document as d
where d.documentAuthors[0].author.lastName = 'Smith'

works as expected.

So, is there a way to do what I want, or even an obscure workaround?
Or will I have to do the sorting in my code, rather than use the database?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 10:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You can use "[]" outside of the where clause.

In Hibernate 2.1, try using the index() function.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 10:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Oh. oops. index() doesn't work for a many-to-many yet, I think.

nah, probably not possible right now. You might need to re-model as a composite-element mapping (in v2.1, still)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2003 12:25 pm 
Newbie

Joined: Fri Sep 12, 2003 4:01 pm
Posts: 19
It looks like this works

Code:
select d from Document as d
     left join d.documentAuthors da
     where da.place=0
     order by da.author.lastName, da.author.firstName


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.