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: <map> - search on index
PostPosted: Mon Nov 19, 2007 4:50 am 
Beginner
Beginner

Joined: Tue Mar 27, 2007 4:54 am
Posts: 47
Hibernate version:
1.2

Hi

When using a map....

<map>
<key ../>
<index .../>
....
</map>

Is it possible to do any kind of search based on the index (=where [index]=xxx) when using a map? Preferable using ICriteria.

I guess this is not possible? Or?

Regards
Roger


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 7:34 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
From section 11.8 of the documentation:

Quote:
Elements of indexed collections (arrays, lists, maps) may be referred to by index (in a where clause only):

from Order order where order.Items[0].id = 1234

select person from Person person, Calendar calendar
where calendar.Holidays['national day'] = person.BirthDay
and person.Nationality.Calendar = calendar

select item from Item item, Order order
where order.Items[ order.DeliveredItemIndices[0] ] = item and order.id = 11

select item from Item item, Order order
where order.Items[ maxindex(order.items) ] = item and order.id = 11

The expression inside [] may even be an arithmetic expression.

select item from Item item, Order order
where order.Items[ size(order.Items) - 1 ] = item

HQL also provides the built-in index() function, for elements of a one-to-many association or collection of values.

select item, index(item) from Order order
join order.Items item
where index(item) < 5


I'm not aware of whether or not this is available in ICriteria but I doubt it.

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 7:56 am 
Beginner
Beginner

Joined: Tue Mar 27, 2007 4:54 am
Posts: 47
Thanks a lot! Sorry, didn't look closely at the doc part regarding HQL.

If someone knows how to accomplish the same thing using ICriteria, I'm glad to know how (or confirm it isn't possible).

/R


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.