2

I am trying to add the following query to the JPA repository @Query

"select st from Strategy st where st.unId= ?1 order by ( st.totalMargin / st.totalRevenue ) desc"

However, this query does not parse due to the "(" brackets in the query.

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 

Is there any way this can be achieved in @Query ?

Jens
  • 67,715
  • 15
  • 98
  • 113
OkraSala
  • 303
  • 4
  • 10

2 Answers2

0

In your Strategy object, u can add a getter :

public double getMarginRatio() {
  return (this.totalMargin / this.totalRevenue);
}

then, your order by statement will become "order by st.marginRatio"

Tristan
  • 8,733
  • 7
  • 48
  • 96
0

Yes with nativeQuery

@Query(value = "select st from STRATEGY st where st.unId= ?1 order by ( st.totalMargin / st.totalRevenue ) desc", nativeQuery = true)
iamiddy
  • 3,015
  • 3
  • 30
  • 33