How to select the sum of multiple count() selections in JPQL
问题 What's the equivalent JQPL statement of the following SQL statement: SELECT (SELECT COUNT(*) FROM foo) + (SELECT COUNT(*) FROM bar) 回答1: You can use the query you stated above along with EntityManager's createNativeQuery function see example class below: package facades; import javax.ejb.LocalBean; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; @Stateless @LocalBean public class CustomFacade {