HQL unexpected token “(” subquery select

五迷三道 提交于 2021-02-11 13:50:21

问题


I have this query. Translate it from my sql query to hql. I have this error "unexpected token: ( near line 2, column"

String query = "SELECT MAX(number)\n" +
        "  FROM (SELECT number FROM EmployeeTripCard \n" +
        "        WHERE EXTRACT(YEAR FROM issueDate) = '2015'\n" +
        "        UNION ALL\n" +
        "        SELECT trip_card_number FROM PostgraduateTripCard\n" +
        "        WHERE EXTRACT(YEAR FROM issueDate) = '2015'\n" +
        "        UNION ALL\n" +
        "        SELECT trip_card_number FROM StudentTripCard \n" +
        "        WHERE EXTRACT(YEAR FROM issueDate) = '2015'\n" +
        "        )";




Integer result = (Integer) getSessionFactory().getCurrentSession().createQuery(query).uniqueResult();

I don't underastand what'w wrong


回答1:


My bad Vytsalo, didnt look at the databse tag. HQL subqueries is not supported on from clauses

Note that HQL subqueries can occur only in the select or where clauses:Hibernate Query Language



来源:https://stackoverflow.com/questions/59925853/hql-unexpected-token-subquery-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!