简体   繁体   中英

JPA Multiple Entity with Collection Query

I have the following in SQL:

SELECT * FROM table2 t2, table1 t1 WHERE t1.id=1 AND t2.t1_id IN(1, 2);

How would I do that in JPA?

I tried:

SELECT t2 FROM Table2 t2, Table1 t1 WHERE t1.id = :t1_id AND t2.t1 IN (t1.t1Collection)

With pseudo classes:

Table1
  private int id;
  private Collection<Table1> t1Collection;

Table2
  private int t2;
  private Table1 t1_id;

But I get:

org.hibernate.exception.SQLGrammarException: could not execute query; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query

尝试使用elements关键字:

SELECT t2 FROM Table2 t2, Table1 t1 WHERE t1.id = :t1_id AND t2.t1 IN elements(t1.t1Collection)

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