tags:

views:

54

answers:

1

Hi there. I need to write some HQL to do the following...

I have 3 tables: club, team and game (column names below)

=School= -id(pk) -name

=Team= -id(pk) -name -club_id(fk)

=Game= -id(pk) -opposition -homeScore -awayScore -team_id(fk)

I need to select the last 20 games played for a specified club...

something like: "select last 20 games from all teams that belong to club X"

Does anyone know how i could do this in HQL?

Thanks.

A: 

it goes something like (untested):

select g from teams t join t.games g where t.club = :club
     order by g.date

In order to restrict the result to the first 20

session.createQuery(theQuery)
     .setEntity('club',club)
     .setMaxResults(20)
     .list();

Trouble with HQL is that it is really had to write it with out actually being able to run the stuff.

Gareth Davis