我有一个带有此查询的SpringBoot应用程序
@Transactional
@Modifying
@Query("update HotelDailyPrice cdp set cdp.price = (select nvl (avg (cp.price),0) "
+ "from HotelPrice cp where cp.hotel = ?1 and cp.updateDate > ?2), cdp.day = ?3 where cdp.hotel = ?1 ")
void updateDailyAveragePrice (Hotel Hotel, Date dayDate, String dayDateString);
但我收到了这个错误:
Caused by: java.lang.IllegalStateException: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode
\-[METHOD_CALL] MethodNode: '('
+-[METHOD_NAME] IdentNode: 'nvl' {originalText=nvl}
\-[EXPR_LIST] SqlNode: 'exprList'
+-[AGGREGATE] AggregateNode: 'avg'
| \-[DOT] DotNode: 'hotel1_.price' {propertyName=price,dereferenceType=PRIMITIVE,getPropertyPath=price,path=cp.price,tableAlias=hotel1_,className=com.hotels
.backend.persistence.domain.backend.HotelPrice,classAlias=cp}
| +-[ALIAS_REF] IdentNode: 'hotel1_.id' {alias=cp, className=com.hotels.backend.persistence.domain.backend.HotelPrice, tableAlias=hotel1_}
| \-[IDENT] IdentNode: 'price' {originalText=price}
\-[NUM_INT] LiteralNode: '0'
在查询
中添加 nvl 后会出现此问题答案 0 :(得分:1)
使用coalesce而不是nvl ...这是jpql等价物
答案 1 :(得分:0)
与sql查询的列不同,您需要引用HQL的类变量。
请参阅已经回答的问题。
No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode HQL