Hibernate version: 2
Mapping documents:
Code:
<class name="User" table="user">
<id name="userId" type="int" column="user_id" unsaved-value="0">
<generator class="identity" />
</id>
<bag name="feeds" table="user_feed" lazy="true" cascade="save-update">
<key column="user_id" />
<many-to-many class="AbstractFeed" column="feed_id" />
</bag>
</class>
The AbstractFeed class has no defined relationship to user.
Query (in HSQL):Code:
select count(*) from AbstractFeed feed, User user
where feed in elements( user.feedsAsList )
and user.userId = 4
and feed.feedId = 30
Name and version of the database you are using: MySQL 4
The generated SQL (show_sql=true):Code:
select count(*) as x0_0_
from feed abstractfe0_, user user1_
where ( abstractfe0_.feed_id in (
select feedsaslis2_.feed_id
from user_feed feedsaslis2_
where user1_.user_id=feedsaslis2_.user_id ) )
and ( user1_.user_id = 4 )
and ( abstractfe0_.feed_id = 37 )
Problem:
I'm trying to determine if a relationship exists between a user and a feed, and thus far the above HSQL is as close as I've been able to come. In fact the query would work if MySQL supported correlated subqueries, but it does not. Is there any way that I can re-write the query to get aroud this?
Thanks for reading!
- Donald