Is DistinctRootEntityResultTransformer supported with HQL? The following is a sample Northwind system where Customer has a set of Orders. Most of the time I want to lazy load the Orders collection, but for this specific case I want to be able to load all of the Customer objects with their Orders collection already initialized.
Code:
IQuery query = Session.CreateQuery("select c from Customer c join fetch c.Orders");
query.SetResultTransformer(new DistinctRootEntityResultTransformer());
IList results = query.List();
When I run this code, I get the following exception:
Code:
Unable to cast object of type 'Northwind.Customer' to type 'System.Object[]'.
I've been able to achieve the same behavior by using a criteria query.
Code:
ICriteria criteria = Session.CreateCriteria(typeof(Customer));
criteria.SetFetchMode("Orders", FetchMode.Join);
criteria.SetResultTransformer(new DistinctRootEntityResultTransformer());
IList results = criteria.List();
However, I really would like to use HQL so that I can take advantage of some other features in more complex queries that require the same principle. Is DistinctRootEntityResultTransformer not supported with HQL?