Hibernate HQL query - complicated
I need to write some HQL to do the following...
I have 3 tables: club, team and game (column names below)
=School= -id(pk) -开发者_如何学JAVAname
=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.
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.
精彩评论