Assuming the banks attribute on user is mapped as "banks" (with getBanks()
and setBanks()...) and you want to search based on a field named "id" in the
Bank object, then do this use this OQL:
"SELECT u FROM User u WHERE u.banks.id = $1"
If doing queries across n:n mappings be sure that the sql element's name is
there on both sides of the relationship. Castor won't complain if it isn't,
but will through errors when trying to query across this type of
relationship if it isn't.
HTH
----- Original Message -----
From: "St�phane Verlet" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, May 01, 2002 3:44 PM
Subject: [castor-dev] Many to many relationship
>
>
> hi
>
> I have 2 classes
> Bank and User
>
> A User can has a collection of banks
>
> When I query for a user , I get my banks ArrayList as expected
>
>
> I am wondering if there is a way to query for users that have a certain
> bank ?
>
> thank you
>
>
>
>
>
>
>
>
> <class name="com.cci.rms.entity.Bank" identity="id">
>
>
> <map-to table="BANK"/>
>
> <field name="id" >
>
> <sql name="bank_id" type="integer"/>
>
> </field>
>
>
>
>
> </class>
>
>
>
>
>
> <class name="com.cci.rms.entity.UserInformation" identity="id">
>
> <map-to table="User"/>
>
> <field name="id" >
>
> <sql name="user_id" type="integer"/>
>
> </field>
>
>
> <field name="banks" type="com.cci.rms.entity.Bank" required="true"
> collection="arraylist">
>
> <sql name="bank_id" many-table="user_bank"
> many-key="user_id" />
>
> </field>
>
>
>
> </class>
>
>
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev