Hi,

I'm working on a presentation on different fetching strategies with
NHibernate, and while preparing the material, I ran into a weird
issue: MultiQuery and Futures seem sensitive to the order of the
queries.

My database is the Microsoft AdventureWorks sample db (with a few
modifications to the data as to present some of the pitfalls involved
in fetching strategies). I generated the classes and mappings with
CodeSmith and tweaked them a bit (removing unnecessary bidirectional
associations and suchlike).

If I run the following queries:


session.CreateQuery("from Product p join fetch p.ProductReviews where
p.id = :id1")
        .SetParameter("id1", productId)
        .Future<Product>();

session.CreateQuery("from Product p join fetch p.Photos pp join fetch
pp.Photo where p.id = :id2")
        .SetParameter("id2", productId)
        .Future<Product>();

var product = session.CreateQuery("from Product where id = :id3")
        .SetParameter("id3", productId)
        .FutureValue<Product>().Value;

product ends up being null, while NHProf shows that a single row is in
fact returned from the db.

(In case you wonder about the Product -> Photos -> Photo mapping,
ProductPhoto is an association class)

However, if I change it to this:

session.CreateQuery("from Product p join fetch p.ProductReviews where
p.id = :id1")
        .SetParameter("id1", productId)
        .Future<Product>();

var productFuture = session.CreateQuery("from Product where id
= :id3")
        .SetParameter("id3", productId)
        .FutureValue<Product>();

session.CreateQuery("from Product p join fetch p.Photos pp join fetch
pp.Photo where p.id = :id2")
        .SetParameter("id2", productId)
        .Future<Product>();

var product = productFuture.Value;

product ends up with the correct value. As far as I can tell, all I
did was change the order of the queries inside the generated
MultiQuery. And, in fact, when I translated it into a straight-up
MultiQuery, I got the same result. Zero results when the "single
product" query was last, one result when it was second to last.

Is this some sort of common error I'm making here?

Also, on a side note: something else isn't quite right here either, as
I'm witnessing the Photo HQL query generating correct-looking SQL and
getting correct-looking results, yet every access to a Photo
association triggers a lazy select.

I'm hoping it's just me. :-)

-Lauri

-- 
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