快速业务通道

hibernate3学习笔记(九) Query及HQL - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-07-04
System.out.println("id \t name/age");73. while (iterator.hasNext()) {74. User user = (User) iterator.next();75. System.out.println(user.getId() + " \t " + user.getName() + "/" + user.getAge());76. }77. }78.}

hibernate3学习笔记(九) Query及HQL(2)

时间:2011-02-02 csdn博客 沈斌

修改User.hbm.XML文件;

1.<?xml version="1.0" encoding="UTF-8"?>2.
3.<!DOCTYPE hibernate-mapping PUBLIC4.    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"5.    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
6.
7.<hibernate-mapping>
8.    <class name="com.hb3.pack_01.model.User" table="user"9.        dynamic-insert="true"10.        dynamic-update="true"11.    >
12.        <id name="id" column="id" type="java.lang.Integer" unsaved-value="null">
13.            <generator class="native" />
14.        </id>
15.16.        <property name="name" column="name" type="java.lang.String" />
17.18.        <property name="age" column="age" type="java.lang.Integer" />
19.    </class>
20.21.    <query name="com.hb3.pack_01.model.User.QueryUser">
22.        <![CDATA[23.            from User as user where user.age >  :minAge24.        ]]>
25.    </query>
26.27.</hibernate-mapping>

新建UserBak类

1.package com.hb3.pack_01.model;2.3.public class UserBak {4.
5.    private String clz = "UserBak";6.    private String name;7.    private Integer age;8.9.    public UserBak() {10.    }11.12.    public UserBak(String name, Integer age) {13.        this.name = name;14.        this.age = age;15.    }16.17.    public String getName() {18.        return name;19.    }20.    public void setName(String name) {21.        this.name = name;22.    }23.    public Integer getAge() {24.        return age;25.    }26.    public void setAge(Integer age) {27.        this.age = age;28.    }29.    public String getClz() {30.        return clz;31.    }32.    public void setClz(String clz) {33.        this.clz = clz;34.    }35.}

hibernate3学习笔记(九) Query及HQL(3)

时间:2011-02-02 csdn博客 沈斌

运行结果:

16:53:02,015  WARN ConfigurationFactory:127 - No configuration found. Configuring ehcache from ehcache-failsafe.xml  found in the classpath: jar:file:/D:/Java/MyEclipse%206.0/workspace/hb3demo/ehcache-1.2.3.jar!/ehcache-failsafe.xml16:53:02,437  WARN EhCacheProvider:93 - Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.16:53:02,468  WARN EhCacheProvider:93 - Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.Hibernate: select user0_.id as id0_, user0_.name as name0_, user0_.age as age0_ from user user0_ order by user0_.age desc, user0_.nameid   name/a

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号