在配置文件中定义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');

相关文章:

  • 2021-07-29
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2021-11-14
  • 2021-07-30
猜你喜欢
  • 2021-11-27
  • 2022-12-23
  • 2021-09-14
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案