-->
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.  [ 5 posts ] 
Author Message
 Post subject: HQL on attribute List<String>
PostPosted: Fri Feb 09, 2007 12:28 pm 
Newbie

Joined: Fri Jun 16, 2006 11:53 am
Posts: 12
Hibernate version:
3.2

Mapping
Works fine. The main class involved is the following
class Playlist{
List<String> _files;
//and appropriate get/set methods

}
Where the collection is mapped using an indexed join table.

Question
I'm trying to come up with a HQL query that will find if there exists any playlists with filenames equal to something OR something OR something

The current (working) HQL I have atm is:

select count(play) from Playlist as play

What I think I want is something of the form:

select count(play) from Playlist as play where play.files.element in ('something', 'somethingelse')

But the latter doesn't work. Anyone has a clue on what syntax I should use for this case?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 12:52 pm 
Newbie

Joined: Fri Jun 16, 2006 11:53 am
Posts: 12
The exception i'm getting:

org.hibernate.QueryException: cannot dereference scalar collection element: element [select count(play) from com.abc.def.ghi.Playlist as play where play.files.element in ('bg800x600.jpg')]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 6:27 pm 
Newbie

Joined: Mon Jan 15, 2007 9:51 am
Posts: 17
I believe this could work:

select count(play)
from Playlist play
join play.files file
where file in ('something', 'somethingelse')

Now I just wish it was possible to pass in an array or List of strings instead of 'something','somethingelse', but that's another story... :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 10:27 am 
Newbie

Joined: Fri Jun 16, 2006 11:53 am
Posts: 12
Hmm, very interesting. I'd gotten something working, but I wasn't entirely satisfied with it:

select count(play) from Playlist as play where 'something' in elements(play.files) or 'somethingelse' in elements(play.files)

Yours is much more elegant. Works fine too. Many thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 14, 2007 3:19 pm 
Newbie

Joined: Mon Jan 15, 2007 9:51 am
Posts: 17
You're welcome, please rate! :)


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