aspose file tools*
The moose likes Object Relational Mapping and the fly likes Error Related to translating the SQL to HQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Error Related to translating the SQL to HQL" Watch "Error Related to translating the SQL to HQL" New topic
Author

Error Related to translating the SQL to HQL

Sumadhur Adapa
Greenhorn

Joined: Dec 13, 2012
Posts: 1
Hi I am new to Hibernate. I am facing the issues while translating the SQL to HQL. Please find below the SQL query which is executing fine.

select distinct Max(A.TRACK_ID) TRACK_ID, A.EVENT_ID, B.ORG_ARPT_CD, B.DEST_ARPT_CD, C.CRITERIA_DEFINITION, C.EVENT_DEFINITION from EVENT_TRACKER A, FLT_MASTER B, EVENT_DEFINITION C, ( select Max(TRACK_ID) TRACK_ID from EVENT_TRACKER group by FLT_DTL_ID ) D where A.FLT_DTL_ID = B.FLT_DTL_ID And A.EVENT_ID = C.EVENT_ID And C.EVENT_DEFINITION is not null And A.TRACK_ID = D.TRACK_ID And C.EVENT_OWNER = 'U292670' group by A.EVENT_ID, B.ORG_ARPT_CD,B.DEST_ARPT_CD,C.CRITERIA_DEFINITION,C.EVENT_DEFINITION


I write down the below mentioned HQL query like

[SELECT DISTINCT MAX(A.id.trackId), A.eventId, B.origin, B.destination, C.criteriaDefinition, C.eventDefinition FROM com.skytech.rmi.services.domain.EventTracker A, com.skytech.rmi.services.domain.FlightDetails B, com.skytech.rmi.services.domain.EventDefinition C , ( SELECT MAX(eventTr.id.trackId) FROM com.skytech.rmi.services.domain.EventTracker eventTr GROUP BY eventTr.id.fltDtlId )as D WHERE A.id.fltDtlId = B.flightDtlId AND A.eventId = C.eventId AND C.eventDefinition IS NOT NULL AND A.id.trackId = D AND C.eventOwner = 'U292670' GROUP BY A.eventId, B.origin, B.destination, C.criteriaDefinition, C.eventDefinition ORDER BY A.id.trackId DESC, A.eventId, B.origin, B.destination]




In place of D (red color)used: D.id.trackId or D.trackId but still the same kind of exception which is mentioned below.
And I am getting the below mentioned exception like

org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 266 [SELECT DISTINCT MAX(A.id.trackId), A.eventId, B.origin, B.destination, C.criteriaDefinition, C.eventDefinition FROM com.skytech.rmi.services.domain.EventTracker A, com.skytech.rmi.services.domain.FlightDetails B, com.skytech.rmi.services.domain.EventDefinition C , ( SELECT MAX(eventTr.id.trackId) FROM com.skytech.rmi.services.domain.EventTracker eventTr GROUP BY eventTr.id.fltDtlId )as D WHERE A.id.fltDtlId = B.flightDtlId AND A.eventId = C.eventId AND C.eventDefinition IS NOT NULL AND A.id.trackId = D AND C.eventOwner = 'U292670' GROUP BY A.eventId, B.origin, B.destination, C.criteriaDefinition, C.eventDefinition ORDER BY A.id.trackId DESC, A.eventId, B.origin, B.destination]
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:258)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
com.skytech.rmi.services.dao.JdbcDashboardDao.getAlertElements(Unknown Source)
com.skytech.rmi.services.dao.JdbcDashboardDao.getAlertData(Unknown Source)
com.skytech.rmi.services.dao.JdbcDashboardDao.getDashboardStatus(Unknown Source)

The below mentioned POJO classes have respective member variables


Please help me in this regard.
Thanks in Advance,
Sumadhur Adapa
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error Related to translating the SQL to HQL