I had originally posted the question on StackOverflow. But am not getting a satisfactory answer.
http://stackoverflow.com/questions/2056856/nhibernate-createquery-and-createcriteria-generating-different-sql-queries I have a Client class and a Report class. A client can have only one Report and a Report can belong to only one client. My database table for Report has the foreign key clientID that points to the primary key of the Client table. I have mapped this relation as a unique foreign key one to one association as mentioned in the documentation. http://nhforge.org/doc/nh/en/index.html#mapping-declaration-onetoone I am facing the problem as explained in http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/11/18/legacy-db-and-one-to-one-relations.aspx A simple hql query to load all clients is forcing one query to be executed to select all clients and then multiple queries to select the reports for each client. However, if I execute the same query crafted using Criteria, instead of doing N selects, it does a join and selects everything in one go. Why are two different types of queries being generated? And more importantly, why is it trying to fetch the Reports? As per the documentation, the default behaviour is to return a proxy that will be lazy loaded. That is, if I ask for the Report property on the client object, only then should it execute the sql for the Report. I just need to query the data for the client. I dont need the report for each client all the times. And Gabriels solution of explicitly specifing the properties that I need from the Client is not really comfortable as there are a lot of properties in Client that I always need. I am new to Nhibernate. Am using the binaries that come with the 614 build of Fluent NHibernate. Have tried with the 2.1 release as well as the binaries that came with the RTM release of FluentNH. I have received a work around as an answer in the SO question. However I would like to know, if this is a bug or am I not understanding how NH works. Thanks!
-- 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.
