带有JPQ

时间:2017-12-13 09:26:00

标签: java jpql

在MySQL中

SELECT SUM(CASE WHEN (t.code = 'ITEM') THEN (SELECT i.amount FROM Billable_Item i WHERE i.Billable_Item_id = ri.billable_Id) ELSE 0 END) FROM Reservation_Item ri JOIN RESERVATIoN r on r.RESERVATION_ID = ri.RESERVATION_ID JOIN billable_Type t on t.billable_Type_id = ri.billable_Type_id WHERE r.reservation_id = xxx

在Hibernate JPQL中

@Query(
    "SELECT SUM(CASE WHEN (t.code = 'ITEM') THEN (SELECT i.amount FROM BillableItem i WHERE i.id = ri.billableId) ELSE 0 END) " +
    "FROM ReservationItem ri JOIN ri.reservation r JOIN ri.billableType t WHERE r.id = :reservationId")

上面的SQL语句在MySQL中运行良好,但是,当转换为Hibernate JPQL时它会出现异常

  

引起:org.hibernate.hql.internal.ast.QuerySyntaxException:意外的AST节点:查询[SELECT SUM(CASE WHEN(t.code ='ITEM')THEN(SELECT i.amount FROM com.flyt.domain .BillableItem i WHERE i.id = ri.billableId)ELSE 0 END)FROM com.flyt.domain.ReservationItem ri JOIN ri.reservation r JOIN ri.billableType t WHERE r.id =:reservationId]       在org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)       在org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)       在org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:79)       在org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:257)       在org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)       在org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138)       在org.hibernate.engine.query.spi.HQLQueryPlan。(HQLQueryPlan.java:104)       在org.hibernate.engine.query.spi.HQLQueryPlan。(HQLQueryPlan.java:79)       在org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)       在org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:222)       在org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:200)       在org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1739)       在org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:291)

0 个答案:

没有答案