I'm running an application in JBoss and Using JPA.
For a report I need a group by query which I expect to return a result set with the开发者_运维问答 following structure example:
count,idA,idB
I did not find a way to implement this in JPA.
What are my best options for implementing this considering I'm developing in JBoss 5, EJB3
You can use a custom holder class and use the NEW
keyword in your query:
SELECT NEW com.mycompany.myapp.MyClass(count, idA, idB)
FROM ...
WHERE ...
Of course, MyClass
needs to have the proper constructor defined.
In the case of Native queries, you can create a dummy entity into which the result set can be mapped to (Native query will not be mapped into an Object unless its a real managed entity). The entity is a dummy as it will not be persisted and it only used for mapping the result set of the native query into this entity.
精彩评论