如何在HQL中编写内联视图?

时间:2012-07-01 02:03:46

标签: java hibernate hql

session.createQuery(" from " +
                "(select att.licenceNo license,driver.driverName drivername" +
                    " from DriverAttendanceDTO att,DriverDetailsDTO driver" +
                    " where att.licenceNo=driver.licenceNo" +
                    " and att.recordStatus='A'" +
                    " and driver.recordStatus='A' )");

Hibernate给了我

Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 7 [ from (select att.licenceNo license,driver.driverName drivername,att.present present from com.vms.dto.DriverAttendanceDTO att,com.vms.dto.DriverDetailsDTO driver where att.licenceNo=driver.licenceNo and att.recordStatus='A' and driver.recordStatus='A' )]
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)

这有什么问题?

1 个答案:

答案 0 :(得分:0)

删除from (...)

session.createQuery("select att.licenceNo license,driver.driverName drivername" +
                    " from DriverAttendanceDTO att,DriverDetailsDTO driver" +
                    " where att.licenceNo=driver.licenceNo" +
                    " and att.recordStatus='A'" +
                    " and driver.recordStatus='A'");