0

私はSQLで次のものを持っています:

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

JPAでそれを行うにはどうすればよいですか?

私は試した:

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

疑似クラスの場合:

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

Table2
  private int t2;
  private Table1 t1_id;

しかし、私は得る:

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

1 に答える 1

3

elementsキーワードを試してください:

SELECT t2 FROM Table2 t2, Table1 t1 WHERE t1.id = :t1_id AND t2.t1 IN elements(t1.t1Collection)
于 2012-09-07T20:17:20.503 に答える