I have following class:
@Entity
@Table(name = "clients")
public class Client extends Model {
@Id
public int id;
@Formula(select = "inv.some_data",
join = "left join (select 1 as some_data) as inv")
public int someData;
public static Finder<String, Client> find =
new Finder<String, Client>(String.class, Client.class);
public static int countClientsWithData() {
return Client.find.where().gt("someData", 0).findRowCount();
}
}
It has someData
field (play framework will generate getters and setters automatically). And also countClientsWithData
uses this field in where
clause. Now if I do
int count = Client.countClientsWithData();
It will throw NullPointerException
while trying to execute query
select count(*) from clients t0 where inv.some_data > ?
Looks like findRowCount
doesn't recognize join in @Formula
annotation. Any thoughts on how to work around this problem?
Updated question: narrowed down problem to findRowCount
call.
So you want the count without using findRowCount() method and without fetching all the data ..
Solution: Copy the same query, and make it on the form select count(*) from ..
and use it to find the count
Example:
If your query is on the form ..
Query: SELECT * FROM clients
Then this line of code Client.find.where().gt("some_data", 0).findRowCount();
will be equivlant to ..
Count Query: SELECT COUNT(*) FROM clients WHERE some_data > 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With