Search code examples
jpql

JPQL Join Query using getter method


"SELECT pub FROM Publisher pub JOIN pub.magazines mag WHERE pub.revenue > 100 "

I'm wondering if I can use method call instead of pub.revenue i.e pub.getRevenue(). Is this possible? Because the revenue variable may be declared private and cannot be accessed directly.


Solution

  • Having revenue variable with private visibility does not limit its usage in JPQL query. You can use it, no matter what is the visibility. So your example should work.

    In general, you cannot call methods from JPQL queries. Reason is that JPQL query translates to the SQL query and there is in no concept of calling methods of Java classes from SQL query.