NHIBernate Custom HQL download

Below is the NHibernate documentation:

15.4. Custom SQL to Load You can also declare your own SQL (or HQL) queries to load entities:

<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 query as discussed earlier. You can reference this named query in the class mapping:

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

      

There is no example for using HQL. I tried to just replace <sql-query>

with <query>

and then replace the SQL query with an HQL query. This results in an "Unknown SQL query unknown" exception. Is there a way to tell it to look for an HQL query instead of an SQL query?

+2


a source to share





All Articles