Hi!
I'm a relatively new Hiberate user and I have a couple of questions regarding what is possible using report queries.
The example I have is a database (eg postgresql) containing TV show information. So I have tables:
- show
- episode which has a show_id FK back to show
I've modeled this in hibernate with a one-to-many relationship (show to episode) and the reverse many-to-one relationship (episode to show).
I have a "Shows" page on which list all the shows, seasons and episodes - ie
Code:
Show A | Episode 1
| Episode 2
| ...
Show B | Episode 1
| Episode 2
| ...
Show C | Episode 1
| Episode 2
| ....
I initially did this using the entities themselves and all was good - as I just queried for the list of shows and then I could loop through them doing...
Code:
List<Show> shows = Dao.getShows(); // "select show from Show s;"
for (Show show : shows) {
for (Episode episode : show.getEpisodes()) {
...
}
}
I then decided to move this to a report query and so created an EpisodeDto and did a query along the lines of...
Code:
select new EpisodeDto(e.show.name, e.title) from Episode e
So to produce my page above my code now loops through the list of EpisodeDto's and I just have to do a bit of fluffing around so I only print the show once.
Now what I would really like to do is have a ShowDto which has attributes:
- String showName;
- List<String> episodeTitle;
where I do a query something like:
Code:
select new ShowDto(show.name, new list(episode.title)) from Show show left join show.episodes episode
Is anything like this do-able?
Thanks in advance!