我已经在JPA存储库中定义了此查询
@org.springframework.data.jpa.repository.Query("select min(cur.volumeUsd24h), max(cur.volumeUsd24h), "
+ "min(marketCapUsd), man(marketCapUsd), "
+ "min(availableTickets), man(availableTickets), "
+ "min(totalTickets), man(totalTickets) "
+ "min(maxTickets), man(maxTickets) "
+ "from Tickets cur ")
Object[] findQueryFiltersValues ();
但是当我启动应用程序时,出现此错误:
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: min near line 1, column 211 [select min(cur.volumeUsd24h), max(
我也尝试过
@Query(value = "select min(cur.volume_usd_24h), max(cur.volume_usd_24h), "
+ "min(market_cap_usd), max(market_cap_usd), "
+ "min(available_tickets), max(available_tickets), "
+ "min(total_tickets), max(total_tickets) "
+ "min(max_tickets), max(max_tickets) "
+ "from tickets cur ",nativeQuery = true)
但是出现编译错误:
Multiple markers at this line
- Syntax error on token ",", [ expected
- Syntax error, insert "]" to complete
Expression
答案 0 :(得分:0)
假设man实际上是max
,则原始查询具有语法错误,这就是异常的原因。 max(totalTickets)
之后没有没有逗号,这使得查询max(totalTickets) min(maxTickets)
。根据发布的代码查看this sample,该代码显示了已执行的更正查询
答案 1 :(得分:-2)
JPA存储库不支持最小,最大功能。
您应该将查询更改为本地sql(将POJO字段替换为数据库列名称)
并添加nativeQuery = true属性。
类似这样的东西
@Query(value = "select min(cur.volume_usd_24h), max(cur.volume_usd_24h), "
+ "min(market_cap_usd), max(market_cap_usd), "
+ "min(available_tickets), max(available_tickets), "
+ "min(total_tickets), max(total_tickets) "
+ "min(max_tickets), max(max_tickets) "
+ "from tickets cur ",nativeQuery = true)