-->
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.  [ 1 post ] 
Author Message
 Post subject: Report query with a list attribute?
PostPosted: Sat May 07, 2011 2:42 am 
Newbie

Joined: Sat May 07, 2011 1:57 am
Posts: 1
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.