[ACCEPTED]-Hibernate Query Syntax exception : org.hibernate.hql.ast.QuerySyntaxException: unexpected token-hibernate
Accepted answer
You should not use explicit "JOIN ON" in 9 HQL. Instead you can use implicit joining 8 in HQL:
SELECT rm.id , rm.routeCode , rm.startPlaceId , rm.endPlaceId , rm.active , rm.linkedRoute
FROM com.abhibus.oprs.pojo.routes.RouteMaster rm
INNER JOIN rm.routeHalts rh WHERE rh.placeId = :PlaceId ORDER BY rm.id ASC
or you can use Theta style for writing 7 join:
SELECT rm.id , rm.routeCode , rm.startPlaceId , rm.endPlaceId , rm.active , rm.linkedRoute
FROM com.abhibus.oprs.pojo.routes.RouteMaster rm, RouteHalts rh
WHERE rm.id = rh.routeId AND rh.placeId = :PlaceId ORDER BY rm.id ASC
Also you can execute your query as 6 native SQL query, not HQL query. For this 5 you should use
session.createSQLQuery(queryText);
instead of
session.createQuery(queryText);
And by the way, may 4 be in your case in is better to fetch whole 3 entity, not separated fields (columns)? For 2 this you can use:
select rm from ...
This will return the List<RouteMaster>
insted 1 of List<Object[]>
.
Change your query likes this;
SELECT rm.id, rm.routeCode, rm.startPlaceId, rm.endPlaceId, rm.active, rm.linkedRoute
FROM RouteMaster rm
INNER JOIN rm.routeHalts AS rh ON rm.id = rh.routeId
WHERE rh.placeId = :PlaceId
ORDER BY rm.id ASC
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.