As for the "select com.id, com.label, com.postCode, com.mayor.name"
part, yes NHibernate can do that. The return type is a list of
object[].

Converting that to partly initialised domain objects is not a feature
of Hibernate, it's a feature of HibernateUtils.find(), which is also
presented in that blog post. And sounds rather dangerous to me.

/Oskar


2011/3/13 Vikram Nayak <[email protected]>:
> The following code snippet is from the following blog post:
> http://www.javalobby.org/articles/hibernate-query-101/
> for hibernate. I was wondering if there is something similar in
> Nhibernate.
>
> --------------------------------------------------------------------------------------------------------------------------------------------------------------
> Finally, I will present a variation on the previous technique, which
> avoids the need to create a new data-transfer class for each query.
> The idea is to retrieve a list of instances of a Hibernate-persisted
> business class, using a given HQL query, but with only a specified set
> of columns being instantiated. This allows fast, light-weight queries
> which return only the minimum necessary information, and avoid complex
> joins in the HQL queries. For example :
>
>  String query =
>                        "select com.id, com.label, com.postCode, com.mayor.name
>                         from Community as com
>                         left join com.mayor
>                         order by com.label ";
>
>  results = HibernateUtils.find(query);
>
>
> This query will return a list of Community objects, but with only the
> 4 specified fields instantiated. Note that this is a powerful
> technique, as the presentation layer may use ordinary business classes
> instead of data transfer objects, without having to know the details
> of the querying techniques being used. T
>
> --------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Thanks,
> Vikram
>
> --
> 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.
>
>

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