views:

217

answers:

0

The following is from the NHibernate documentation:

15.4. Custom SQL for loading You may also declare your own SQL (or HQL) queries for entity loading:

<sql-query name="person">
    <return alias="pers" class="Person" lock-mode="upgrade"/>
    SELECT NAME AS {pers.Name}, ID AS {pers.Id}
    FROM PERSON
    WHERE ID=?
    FOR UPDATE
</sql-query>

This is just a named query declaration, as discussed earlier. You may reference this named query in a class mapping:

<class name="Person">
    <id name="Id">
        <generator class="increment"/>
    </id>
    <property name="Name" not-null="true"/>
    <loader query-ref="person"/>
</class>

There isn't an example given for using HQL. I tried to simply replace <sql-query> with <query> and then replace the SQL query with an HQL query. This results in the exception "Named SQL query not known". Is there a way to tell it to look for an HQL query instead of an SQL query?