hey,

Firstly i am new to nhibernate, but consider myself pretty experienced
in writing SQL queries.

i have two tables. one called records and one called userrecords.
records has the relationship that a record contains multiple
userrecords.

Will explain with an example.
if there are 10 records and 10 users then you can expect to see 100
user records. One for each combination. A unique index exists on the
userrecords table constraining this.

So if you were to right the query in sql it would be..assuming you are
after the records and user records for user 2.

select * from records r
   left outer join userrecords ur on r.recordid = ur.recordid and
ur.userid = 2

this will join the tables correctly so that it will still give you one
user record for each record. If you included the userid as a filter
and there was only 5 user records for user 2 then you would only get 5
rows returned and this would not be correct.

Therefore i tried to right this in hql.

from records r
   left join fetch r.userrecords with r.userid = :userid

However I was given the error.

Semantic Exception -> with-clause not allowed on fetched associations;
use filters

Also if i don't do the fetch the query works, however when it does the
lazy fetch it doesn't include the userid so the results are incorrect.

Is my model not correct or should I be allowed to do this?
Open to suggestions.

Cheers,

Adam

--

You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.


Reply via email to