I have a class Person, which is associated with Person many-to-many associaton,
<hibernate-mapping>
<class
name="src.model.Person"
table="PERSONS"
>
.
.
.
<set
name="friends"
table="FRIENDS_PERSON"
lazy="true"
cascade="all"
sort="unsorted"
>
<key
column="HAVE_A_FRIEND"
>
</key>
<many-to-many
class="src.model.Person"
column="IS_A_FRIEND"
outer-join="auto"
/>
</set>
</hibernate-mapping>
I need to write a query which will check if given two person are friends. In native SQL this query would be something like this.
SELECT COUNT(*) FROM FRIENDS_PERSON WHERE have_a_friend=:id1 AND is_a_friend=:id2");
How to write it in Hibernate, or how to use this query as a native sql query in hibernate?
|