Try "SELECT p FROM Person p WHERE :account member of p.bankAccounts". Should work.

Cheers,
Matthias

[EMAIL PROTECTED] wrote:
Hi,

let's assume this object model:
* a person has a address (one-to-one)
* a person has many bankaccounts (one-to-many)

Let's say person1 and bankaccount1 are persistent entities of their
respective types.

This query works like a charm:
Query query = entityManager.createQuery("SELECT p FROM Person p WHERE
p.address = :address");
query.setParameter("address", address1);

However, this query raises an exception:
Query query = entityManager.createQuery("SELECT p FROM Person p, IN
(p.bankAccounts) acc WHERE acc = :account");
query.setParameter("account", bankaccount1);

The stacktrace:
Exception in thread "main" <openjpa-1.1.0-r422266:657916 nonfatal user
error> org.apache.openjpa.persistence.ArgumentException: The parameter
"account" is of type "oopex.openjpa1.jpa.queries.model.BankAccount",
but the declaration in the query is for type "java.util.Set".
        at
org.apache.openjpa.persistence.QueryImpl.validateParameter(QueryImpl.java:270)
        at
org.apache.openjpa.persistence.QueryImpl.validateParameters(QueryImpl.java:257)
        at
org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:231)
        at
org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:277)
        at
oopex.openjpa1.jpa.queries.ByEntityMain.querytomanyrelationship(Unknown
Source)
        at oopex.openjpa1.jpa.queries.ByEntityMain.main(Unknown Source)

What puzzles me is, that "acc" is recognized as "java.util.Set" but
indeed should be BankAccount (according to chapter 4.4.6 of
JSR220-persistence).

I know that there is nothing about such queries in the JPA specification
and the recommended way is to compare the primary key values.
Is this query nevertheless possible?

Kindly appreciate your help,
Frank






Reply via email to