ejbql

How to select the sum of multiple count() selections in JPQL

穿精又带淫゛_ 提交于 2019-12-23 15:59:58
问题 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 {

Passing two parameters to a named query

眉间皱痕 提交于 2019-12-02 11:34:24
问题 I have the following namedquery over my entity "Intervention ": @NamedQuery(name = "Intervention.findNextMission", query = " SELECT i FROM Intervention i WHERE i.heureDebut> :DateToBeSpecified and i.idAgent= :idAgent")` i dont know how to call this query in my code by passing two parameters : date,id. Normally it should be like this : List <Intervention> ListOfInterventions = em.createNamedQuery("Intervention.findNextMission").setParameter().getResultList(); what to put between the

Hibernate (JPA) how to do an eager query, loading all child objects

自古美人都是妖i 提交于 2019-11-30 01:46:14
Relating to my earlier question , I want to ensure all the child objects are loaded as I have a multiple threads that may need to access the data (and thus avoid lazy loading exceptions). I understand the way to do this is to use the "fetch" keyword in the query (EJB QL). Like this: select distinct o from Order o left join fetch o.orderLines Assuming a model with an Order class which has a set of OrderLines in it. My question is that the "distinct" keyword seems to be needed as otherwise I seem to get back an Order for each OrderLine . Am I doing the right thing? Perhaps more importantly, is

Hibernate (JPA) how to do an eager query, loading all child objects

天大地大妈咪最大 提交于 2019-11-28 22:35:09
问题 Relating to my earlier question, I want to ensure all the child objects are loaded as I have a multiple threads that may need to access the data (and thus avoid lazy loading exceptions). I understand the way to do this is to use the "fetch" keyword in the query (EJB QL). Like this: select distinct o from Order o left join fetch o.orderLines Assuming a model with an Order class which has a set of OrderLines in it. My question is that the "distinct" keyword seems to be needed as otherwise I