0

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

1 Answer 1

3

Try the elements keyword:

SELECT t2 FROM Table2 t2, Table1 t1 WHERE t1.id = :t1_id AND t2.t1 IN elements(t1.t1Collection)
Sign up to request clarification or add additional context in comments.

1 Comment

Just a clarification: IN elements is a Hibernate-specific syntax. The JPA corollary is member of:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.