I am new to ORM and I need some help understanding something.
Suppose I have the following standard SQL query:
SELECT *, COUNT(test.testId) AS noTests FROM inspection LEFT JOIN test ON inspection.inspId = test.inspId GROUP BY inspection.inspId
which I want to use in JPA.
I have an inspection object with a one-to-many relationship to the test object. (validation has many tests) I tried to write this in JPQL:
Query query = em.createQuery("SELECT insp, COUNT(???what???) " + "FROM Inspection insp LEFT JOIN insp.testList " + "GROUP BY insp.inspId");
1) How to write a COUNT sentence? I would have to use count for items from the test table, but testList is a collection, so I cannot do something like COUNT(insp.testList.testId)
2) Assuming 1 is allowed, what type of object will be returned. It will definitely not be subject to inspection ... How to use the result?
java sql jpa
Bogdan
source share