简体   繁体   中英

How to transfer SQL Select Subquery to JPQL?

I have formulated an SQL query that I need to translate into JPQL. The query contains a subquery in the SELECT clause, and also selects all rows from the same table that is contained in the subquery.

The following is an example of the SQL query that I am trying to translate:

SELECT table.* FROM TABLE table, (SELECT * FROM TABLE table1 WHERE ... ) table1 WHERE table.id >= table1.id

The part that I am having difficulties with is the table that I am creating using the subquery SELECT table.* FROM TABLE table, (SELECT * FROM TABLE table1 WHERE ... ) table1 . The WHERE clause in the subquery is clear how to translate.

The way I currently have tried to translate the query is:

SELECT t FROM Table t, t1 FROM Table t1 WHERE ... WHERE t.id >= t1.id 

The error I am getting when trying this is:

org.eclipse.persistence.jpa.jpql.parser.NullExpression cannot be cast to org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable

Any help or suggestions would be appreciated :D

Well.... I guess I found the answer. It's not possible to implement such named queries as explained in this post: JPA/hibernate subquery in from clause

I will stick to a native query instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM