开发者

How Can I Query a DB for ResultSet which is not Mapped into an Entity(JPA, JBoss)

开发者 https://www.devze.com 2022-12-20 08:54 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号