用于WITH子句的JPA Criteria API和FROM子句中的子查询

时间:2021-03-24 22:30:03

I`m new to JPA and I would like to implement a query that contains WITH clause, and also subquery in FROM clause by using JPA Criteria API, for example:

我是JPA的新手,我想通过使用JPA Criteria API实现包含WITH子句的查询,以及FROM子句中的子查询,例如:

WITH A AS(...) SELECT a1,a2 FROM A

and also:

SELECT b1, b2 FROM (SELECT c1,c2 FROM ...)

How do I supposed to achieve this goal by using JPA Criteria? Or is there any alternative solution is fine.

我如何使用JPA Criteria实现这一目标?或者有任何替代解决方案是好的。

thanks for helping

谢谢你的帮助

1 个解决方案

#1


2  

This is not possible with JPQL/HQL and the reason is simple, this is not an entity based approach. The core concept for ORM's are entities and they operate on that level.

使用JPQL / HQL是不可能的,原因很简单,这不是基于实体的方法。 ORM的核心概念是实体,它们在该级别上运行。

There's nothing wrong with plain SQL if you want to have efficient queries, just make sure you understand the implications using it.

如果您想要有效查询,那么纯SQL没有任何问题,只需确保您了解使用它的含义。

#1


2  

This is not possible with JPQL/HQL and the reason is simple, this is not an entity based approach. The core concept for ORM's are entities and they operate on that level.

使用JPQL / HQL是不可能的,原因很简单,这不是基于实体的方法。 ORM的核心概念是实体,它们在该级别上运行。

There's nothing wrong with plain SQL if you want to have efficient queries, just make sure you understand the implications using it.

如果您想要有效查询,那么纯SQL没有任何问题,只需确保您了解使用它的含义。