java - Hibernate Criteria join to table containing foreign key -
i have 2 tables:
client (clientid, firstname, lastname, gender) event (clientid, eventid)
i need represent query similar following using criteria:
select c.clientid, c.firstname, c.lastname, c.gender, max(eventid) client c join event e on c.clientid = e.clientid group c.clientid, c.firstname, c.lastname, c.gender
i have tried this:
final criteria criteria = session.createcriteria(client.class); criteria.setfetchmode("event", fetchmode.join); criteria.setprojection(projections.projectionlist().add(projections.groupproperty("clientid")).add(projections.max("eventid")));
but throws exception on last line message:
hibernatequeryexception: not resolve property: eventid of: client
how can specify join between client
table contains no column related event table clientid
column on event
table foreign key client
table?
as can see, it's driven off client
table , need select maximum eventid
event
table. also, mentioned, trying make change existing criteria query based on client
class. used retrieve columns active clients. need add 1 column query results - maximum eventid
.
use alias
criteria criteria = session.createcriteria(event.class, "et"). createalias("et.client", "ct"). setprojection(projections.projectionlist(). add(projections.groupproperty("et.clientid")). add(projections.max("et.eventid")));
for more details on criteria, refer criteria queries
Comments
Post a Comment