This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HQL: entity/entities in set of entities

 
Stefan Anderssson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm stuck on a HQL-query. These are the entities I have:

Entity - Event
Set<Performer> performers

Entity - Performer
Set<Style> styles

Entity - Style
Genre genre

Entity - Genre
String name
etc.

Getting a Set of Events from a Style-entity works well with something like this:
FROM Event AS event WHERE :style IN ELEMENTS(event.performers.styles)

What I'd also like to do is to get Events from a Genre-entity:
FROM Event AS event WHERE :genre ??? event.performers.style(s?).genre

I hope you get what I'm looking for. I guess the question marks above are the parts I need to sort out.

And I wouldn't mind being able to get Events from a Set of Genres, which would be something like
FROM Event AS event WHERE :genres ??? event.performers.style(s?).genre

Where :genre would be Set<Genre>

Thanks!
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you should stand on your head, then you might think backwards to how you are thinking now and totally see an answer. ;)

Actually that might work, but what about flipping things here

Try

FROM Event e JOIN e.performers p JOIN p.genre g WHERE g IN (:genres)

The you have a List<Genre> genres

You then have a Query object you call

query.setParameterList(genres);

Then run the query.

Mark
 
Stefan Anderssson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I think I have been standing on my head for a while, trying to de-SQL-ize myself.

I had to make some adjustments to the solution above, but once I started JOINing it was pretty easy to figure out.

I had to go for something like:
FROM Event e JOIN e.performers p JOIN p.styles s JOIN s.genre g WHERE g IN (:genres)
...since genre is an entity in Style.

Thanks again.

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic