I'm new to JPA and JPQL, so forgive me is this is simple an I'm simply missing something small.
Assume that I have the following (T-SQL):
CREATE TABLE tblCustomer (id int IDENTITY(1,1) NOT NULL, CustName nvarchar(50) NOT NULL, CONSTRAINT tblCustomer_PK PRIMARY KEY NONCLUSTERED (id ASC));
INSERT INTO tblCustomer (CustName) VALUES ('McDonalds');
INSERT INTO tblCustomer (CustName) VALUES ('Lowes');
CREATE TABLE tblOrder (id int IDENTITY(1,1) NOT NULL, custID int NOT NULL, status nvarchar(10) NOT NULL, CONSTRAINT tblOrder_PK PRIMARY KEY NONCLUSTERED (id ASC));
I have entities defined (tblCustomer <--> Customer, tblOrder <--> Order).
I want to do the equivalent of:
SELECT tblCustomer.id, tblCustomer.CustName, COUNT(tblOrder.id) FROM tblCustomer LEFT OUTER JOIN tblOrder ON tblCustomer.id = tblOrder.custID WHERE tblOrder.status <> 'Closed' GROUP BY tblCustomer.id, tblCustomer.CustName
but in JPA / JPQL.
I've looked at: How do I count the number of rows returned by subquery? and several other StackOverflow and other questions.
I'm either ending up with a count of all orders (i.e. tblOrder.status <> 'Closed' not being applied), or I'm ending up with a count of all closed orders without the join being applied.
Any thoughts?