I am using two identical JPQL NamedQueries, except that one is a COUNT. Here are the queries:

select i from IssueRingReqsBrit i where i.ringDataRequest = 'I' and i.onRingIssue = 'Y' and i.noCardIssued = 0

select COUNT(i) from IssueRingReqsBrit i where i.ringDataRequest = 'I' and i.onRingIssue = 'Y' and i.noCardIssued = 0

IssueRingReqsBrit is a view.

The first query is returning a list of 6, which is correct.

The second query, the count, return 0.

Databased being used is Oracle. Using Glassfish with Eclipselink. Shared cache mode on the PU is set to none.

Using native queries in Oracle, the correct values are returned.

Below is the code I use to execute the queries, and check the results. There is no other code between these lines, they were copy and pasted as they are in the Java.

query = em.createNamedQuery("IssueRingReqsBrit.onRingIssue_toSend_initial");

System.out.println("Size: " + query.getResultList().size() );


//ringingRequestRingIssueYesToSendInitial
query = em.createNamedQuery("IssueRingReqsBrit.onRingIssue_toSend_initial_count");


ringingRequestRingIssueYesToSendInitial = ((Long)query.getSingleResult()).intValue();

System.out.println("ringingRequestRingIssueYesToSendInitial = " + ringingRequestRingIssueYesToSendInitial);

Any suggestions are appreciated.

有帮助吗?

解决方案

Based on the JPQL Language reference, in the COUNT function, the path expression that is the argument to the aggregate function must terminate in a state-field. The path expression argument to COUNT may terminate in either a state-field or a association-field, or the argument to COUNT may be an identification variable. So try something like this

select COUNT(i.<field>) from IssueRingReqsBrit i where i.ringDataRequest = 'I' and i.onRingIssue = 'Y' and i.noCardIssued = 0

COUNT returns Long.

Make use you are returning the resulat in a Long.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top