开发者

NHibernate Custom HQL for loading

开发者 https://www.devze.com 2022-12-29 04:52 出处:网络
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:

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>
    <pro开发者_运维技巧perty 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?

0

精彩评论

暂无评论...
验证码 换一张
取 消