我正在尝试将以下查询添加到JPA存储库@Query
"select st from Strategy st where st.unId= ?1 order by ( st.totalMargin / st.totalRevenue ) desc"
但是,由于"("括号在查询中),此查询不会解析。
The error thrown while bean initialization is
Caused by: <openjpa-2.2.2-r422266:1468616 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: "Encountered "(" at
在@Query中有什么办法可以实现吗?
答案 0 :(得分:0)
在您的策略对象中,您可以添加一个getter:
public double getMarginRatio() {
return (this.totalMargin / this.totalRevenue);
}
然后,您的订单语句将变为&#34; order by st.marginRatio
&#34;
答案 1 :(得分:0)
是的,使用nativeQuery
@Query(value = "select st from STRATEGY st where st.unId= ?1 order by ( st.totalMargin / st.totalRevenue ) desc", nativeQuery = true)