JPQL JOINS with nested SELECT

前端 未结 2 1964
Happy的楠姐
Happy的楠姐 2020-12-20 17:44

Can I do something like this on JPQL?

SELECT NEW com.MyDTO(p.a, p.b, q.c, q.d)
FROM
(SELECT r.* FROM MyDTO1 r ) p
LEF         


        
相关标签:
2条回答
  • 2020-12-20 18:19

    Yes you can!

    You have to use native queries. Here is an example:

    emf = Persistence.createEntityManagerFactory("TEST")    
    EntityManager em = emf.createEntityManager();
    String queryString = "SELECT ID FROM ( SELECT * FROM ADDRESS WHERE ID < 0)";
    Query query = em.createNativeQuery(queryString);
    List<BigDecimal> result = query.getResultList();
    
    0 讨论(0)
  • 2020-12-20 18:31

    No, you can't. Quote from the documentation:

    Note that HQL subqueries can occur only in the select or where clauses.

    0 讨论(0)
提交回复
热议问题