Hibernate Criteria join to table containing foreign key

abhaykochar

New Member
I have two tables:\[code\]Client (clientId)Event (clientId, eventId)\[/code\]I need to represent a query similar to the following using Criteria:\[code\]SELECT c.clientId, MAX(eventId)FROM Client c JOIN Event e ON c.clientId = e.clientIdGROUP BY c.clientId\[/code\]I have tried this:\[code\]final Criteria criteria = session.createCriteria(Client.class);criteria.setFetchMode("Event", FetchMode.JOIN);criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("clientId")).add(Projections.max("eventId")));\[/code\]but it throws an exception on the last line with the message:HibernateQueryException: could not resolve property: eventId of: ClientHow can I specify the join between the Client table which itself contains no column related to the Event table but the clientId column on the Event table is a foreign key back into the Client table?
 
Top