学海无涯

记录我的程序人生...

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

在配置文件中定义query

xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

    <class name="onlyfun.caterpillar.User" table="USER">

        <id name="id" type="string">
            <column name="user_id" sql-type="char(32)" />
            <generator class="uuid.hex"/>
        </id>

        <property name="name" type="string" not-null="true">
            <column name="name" length="16" not-null="true"/>
        </property>

        <property name="sex" type="char"/>

        <property name="age" type="int"/>

    </class>

    <query name="onlyfun.caterpillar.queryUser">
        <![CDATA[
            select user.name from User as user where user.age = :age and user.sex = :sex
        ]]>
    </query>

</hibernate-mapping>

code
Query query = session.getNamedQuery("onlyfun.caterpillar.queryUser");
query.setInteger("age", 25);
query.setCharacter("sex", 'M');
posted on 2005-02-21 13:25  josson  阅读(837)  评论(0编辑  收藏  举报