`
高级java工程师
  • 浏览: 410472 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

hql语句集合

阅读更多
/**
 * 
 */
package com.b510.example;
 
import java.util.Iterator;
import java.util.List;
import java.util.Map;
 
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Query;
import org.hibernate.Session;
 
/**
 * 
 * @author XHW
 * 
 * @date 2011-6-18
 * 
 */
public class HibernateTest {
 
 /**
  * @param args
  */
 public static void main(String[] args) {
  HibernateTest test = new HibernateTest();
  test.where();
  test.function();
  test.update();
  test.jiaoChaCheck();
  test.innerJoin();
  test.QBC();
  test.leftOuterJoin();
  test.rightOuterJoin();
 }
 

 public void where() {
  // 使用where查询
  Session session = HibernateSessionFactoryUtil.getSessionFactory()
    .openSession();
  session.beginTransaction();
  Query query = session
    .createQuery("from User where id not between 200 and 2000");
  List<User> list = query.list();
 
  for (User user : list) {
   System.out.println(user.getId() + user.getUsername());
  }
  // 投影查询 中使用where子句
  query = session.createQuery("select username from User where id=2");
  List<String> listname = query.list();
 
  for (String name : listname) {
   System.out.println(name);
  }
  // in查询
  query = session
    .createQuery("from User where username in ('Hongten','Hanyuan','dfgd')");
  List<User> listin = query.list();
 
  for (User user : listin) {
   System.out.println(user.getId() + user.getUsername());
  }
  // like查询
  query = session.createQuery("from User where username not like 'Hon%'");
  List<User> listlike = query.list();
 
  for (User user : listlike) {
   System.out.println(user.getId() + user.getUsername());
  }
  // null查询
  query = session.createQuery("from User where password is null");
  List<User> listnull = query.list();
 
  for (User user : listnull) {
   System.out.println(user.getId() + user.getUsername());
  }
  // and查询
  query = session
    .createQuery("from User where password is not null and id<5");
  List<User> listand = query.list();
 
  for (User user : listand) {
   System.out.println(user.getId() + user.getUsername()
     + user.getPassword());
  }
  // order by
  query = session.createQuery("from User order by username,id desc");
  List<User> listorderby = query.list();
 
  for (User user : listorderby) {
   System.out.println(user.getId() + user.getUsername());
  }
  // 使用"?"号 作为参数占位符,一条HQL语句中可以使用多个?
  // query.setInteger(0,2)
  // query.setString(0,"Hongten")
  query = session
    .createQuery("select username from User where username=?");
  query.setString(0, "Hongten");
  List<String> listwenhao = query.list();
  for (String name : listwenhao) {
   System.out.println(name);
  }
 
  session.getTransaction().commit();
 
 }
 
 public void function() {// 把大写字母转化为小写字母
  // 作用可以用在:比如在一个用户注册的程序中,大小写不容易区分,但是全部转化为小写后就可以很容易进行比较
  Session session = HibernateSessionFactoryUtil.getSessionFactory()
    .openSession();
  session.beginTransaction();
  // 输出原始的数据
  Query query = session.createQuery("select username from User");
  List<String> list = query.list();
 
  for (String name : list) {
   System.out.println(name);
  }
  System.out.println("-------------------------------------------");
  // 输出的数据全部转化为小写
  query = session.createQuery("select lower(username) from User");
  List<String> listChange = query.list();
 
  for (String name : listChange) {
   System.out.println(name);
  }
  session.getTransaction().commit();
 }
 
 public void update() {
  Session session = HibernateSessionFactoryUtil.getSessionFactory()
    .openSession();
  session.beginTransaction();
  Query query = session
    .createQuery("update User set username='洪伟1231' where id=?");
  query.setInteger(0, 3);
  int rowCount = query.executeUpdate();
  System.out.println(rowCount);
  session.getTransaction().commit();
 }
 
 public void operateProfile() {// 对profile这个类执行HQL语句操作
  Session session = HibernateSessionFactoryUtil.getSessionFactory()
    .openSession();
  session.beginTransaction();
  // 执行查询操作
  Query query = session.createQuery("from Profile");
  List<Profile> list = query.list();
  for (Profile profile : list) {
   System.out.println(profile.getId() + profile.getEmail()
     + profile.getAddress() + profile.getMobile()
     + profile.getPostcode());
  }
  // 执行删除操作
  query = session.createQuery("delete from Profile where id=?");
  query.setInteger(0, 3);
  int rowCount = query.executeUpdate();
  System.out.println(rowCount);
  session.getTransaction().commit();
 }
 
 public void jiaoChaCheck() {//交叉查询
  //这种方法查询出来的结果是笛卡尔积,对于我们开发中没有多大用处
  Session session = HibernateSessionFactoryUtil.getSessionFactory()
    .openSession();
  session.beginTransaction();
  Query query=session.createQuery("from User,Profile");
  
  List<Object[]> list=query.list();
  
  for(Object[] values:list){
   User user=(User)values[0];
   System.out.print("ID :"+user.getId()+",UserName:"+user.getUsername()+",Password:"+user.getPassword());
   Profile profile=(Profile)values[1];
   System.out.println(profile.getEmail()+profile.getMobile()+profile.getAddress()+profile.getPostcode());
  }
  
  session.getTransaction().commit();
 }
 
 public void innerJoin(){//内连接查询
  /**
   * 下面三种hql语句都是可以得到相同的结果
   * String hql="select p from Profile as p inner join p.user";
   * 在下面的hql语句中加入"fetch"后,此hql语句变为了"迫切HQL"语句,这样的查询效率要比上面的hql语句要高
   * String hql="select p from Profile as p inner join fetch p.user";
   * 
   * String hql="select p from Profile p,User u where p.user=u";
   * String hql="select p from Profile p,User u where p.user.id=u.id";
   *  
   */  
  Session session = HibernateSessionFactoryUtil.getSessionFactory()
    .openSession();
  session.beginTransaction();
  String hql="select p from Profile as p inner join fetch p.user";
  //String hql="select p from Profile p,User u where p.user=u";
  //String hql="select p from Profile p,User u where p.user.id=u.id";
  Query query=session.createQuery(hql);
  List<Profile> list=query.list();
  for(Profile p:list){
   System.out.println("ID:"+p.getUser().getId()+"   Username: "+p.getUser().getUsername()+"   Email: "+p.getEmail()+",   Address: "+p.getAddress());
  }
  session.getTransaction().commit();
  }
 
 public void QBC(){//QBC中实现内连接查询
  Session session=HibernateSessionFactoryUtil.getSessionFactory().openSession();
  session.beginTransaction();
  Criteria criteria=session.createCriteria(Profile.class).createCriteria("user");
  List<Profile> list=criteria.list();
  
  for(Profile p:list){
   System.out.println("ID:"+p.getUser().getId()+"   Username: "+p.getUser().getUsername()+"   Email: "+p.getEmail()+",   Address: "+p.getAddress());
  }
  //QBC中实现外连接
  System.out.println("##################################################");
  criteria=session.createCriteria(Profile.class).setFetchMode("user", FetchMode.JOIN);
  List<Profile> listp=criteria.list();
  
  for(Profile p:list){
   System.out.println("ID:"+p.getUser().getId()+"   Username: "+p.getUser().getUsername()+"   Email: "+p.getEmail()+",   Address: "+p.getAddress());    
  }  
  session.getTransaction().commit();
 }
 
 public void leftOuterJoin(){//左外连接
  /**
   * String hql="select p from Profile p left outer join p.user order by p.user.id";
   * 在下面的hql语句中加入"fetch"后,此hql语句变为了"迫切HQL"语句,这样的查询效率要比上面的hql语句要高
   * String hql="select p from Profile p left outer join fetch p.user order by p.user.id";
   *
   * String hqlu="select u from User u left outer join u.profiles";
   *  在下面的hql语句中加入"fetch"后,此hql语句变为了"迫切HQL"语句,这样的查询效率要比上面的hql语句要高
   * String hqlu="select u from User u left outer join fetch u.profiles";
   */
  Session session=HibernateSessionFactoryUtil.getSessionFactory().getCurrentSession();
  session.beginTransaction();
  String hql="select p from Profile p left outer join fetch p.user order by p.user.id";
  Query query=session.createQuery(hql);
  
  List<Profile> list=query.list();
  for(Profile p:list){
   System.out.println("ID:"+p.getUser().getId()+"   Username: "+p.getUser().getUsername()+"   Email: "+p.getEmail()+",   Address: "+p.getAddress());
  }
  
  System.out.println("-------------------------------------");
  String hqlu="select u from User u left outer join fetch u.profiles";
  query=session.createQuery(hqlu);
  
  List<User> listu=query.list();
  for(User u:listu){
   System.out.println(u.getId()+u.getUsername()+u.getProfiles());
  }
  session.getTransaction().commit();
   
 }
 
 public void rightOuterJoin(){//右外连接
  Session session=HibernateSessionFactoryUtil.getSessionFactory().getCurrentSession();
  session.beginTransaction();
  String hql="select u from User u right outer join u.profiles order by u.id";
  Query query=session.createQuery(hql);
  
  List<User> listu=query.list();
  for(User user:listu){
   System.out.println(user.getId()+user.getUsername()+user.getProfiles());
  }
  
  session.getTransaction().commit();
   
 }
 
}

结果:
 
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: 
    select
        user0_.id as id0_,
        user0_.username as username0_,
        user0_.password as password0_ 
    from
        users.user user0_ 
    where
        user0_.id not between 200 and 2000
1hongten
2hanyuan
3hongwei
4mingliu
5shouzhang
Hibernate: 
    select
        user0_.username as col_0_0_ 
    from
        users.user user0_ 
    where
        user0_.id=2
hanyuan
Hibernate: 
    select
        user0_.id as id0_,
        user0_.username as username0_,
        user0_.password as password0_ 
    from
        users.user user0_ 
    where
        user0_.username in (
            'Hongten' , 'Hanyuan' , 'dfgd'
        )
1hongten
2hanyuan
Hibernate: 
    select
        user0_.id as id0_,
        user0_.username as username0_,
        user0_.password as password0_ 
    from
        users.user user0_ 
    where
        user0_.username not like 'Hon%'
2hanyuan
4mingliu
5shouzhang
Hibernate: 
    select
        user0_.id as id0_,
        user0_.username as username0_,
        user0_.password as password0_ 
    from
        users.user user0_ 
    where
        user0_.password is null
Hibernate: 
    select
        user0_.id as id0_,
        user0_.username as username0_,
        user0_.password as password0_ 
    from
        users.user user0_ 
    where
        (
            user0_.password is not null
        ) 
        and user0_.id<5
1hongten123
2hanyuan5645645
3hongwei5645645
4mingliu5645645
Hibernate: 
    select
        user0_.id as id0_,
        user0_.username as username0_,
        user0_.password as password0_ 
    from
        users.user user0_ 
    order by
        user0_.username,
        user0_.id desc
2hanyuan
1hongten
3hongwei
4mingliu
5shouzhang
Hibernate: 
    select
        user0_.username as col_0_0_ 
    from
        users.user user0_ 
    where
        user0_.username=?
hongten
Hibernate: 
    select
        user0_.username as col_0_0_ 
    from
        users.user user0_
hongten
hanyuan
hongwei
mingliu
shouzhang
-------------------------------------------
Hibernate: 
    select
        lower(user0_.username) as col_0_0_ 
    from
        users.user user0_
hongten
hanyuan
hongwei
mingliu
shouzhang
Hibernate: 
    update
        users.user 
    set
        username='Hongwei1231' 
    where
        id=?
1
Hibernate: 
    select
        user0_.id as id0_0_,
        profile1_.id as id1_1_,
        user0_.username as username0_0_,
        user0_.password as password0_0_,
        profile1_.user_id as user2_1_1_,
        profile1_.email as email1_1_,
        profile1_.phone as phone1_1_,
        profile1_.mobile as mobile1_1_,
        profile1_.address as address1_1_,
        profile1_.postcode as postcode1_1_ 
    from
        users.user user0_,
        users.profile profile1_
ID :1,UserName:hongten,Password:123hongtenzone@foxmail.com45464Guangzhoushi65465
ID :1,UserName:hongten,Password:123hanyuan@foxmail.com45648255GuangzhoushiDianbian65465
ID :1,UserName:hongten,Password:123hanyuan@foxmail.com45648255GuangzhoushiDianbian65465
ID :2,UserName:hanyuan,Password:5645645hongtenzone@foxmail.com45464Guangzhoushi65465
ID :2,UserName:hanyuan,Password:5645645hanyuan@foxmail.com45648255GuangzhoushiDianbian65465
ID :2,UserName:hanyuan,Password:5645645hanyuan@foxmail.com45648255GuangzhoushiDianbian65465
ID :3,UserName:Hongwei1231,Password:5645645hongtenzone@foxmail.com45464Guangzhoushi65465
ID :3,UserName:Hongwei1231,Password:5645645hanyuan@foxmail.com45648255GuangzhoushiDianbian65465
ID :3,UserName:Hongwei1231,Password:5645645hanyuan@foxmail.com45648255GuangzhoushiDianbian65465
ID :4,UserName:mingliu,Password:5645645hongtenzone@foxmail.com45464Guangzhoushi65465
ID :4,UserName:mingliu,Password:5645645hanyuan@foxmail.com45648255GuangzhoushiDianbian65465
ID :4,UserName:mingliu,Password:5645645hanyuan@foxmail.com45648255GuangzhoushiDianbian65465
ID :5,UserName:shouzhang,Password:5645645hongtenzone@foxmail.com45464Guangzhoushi65465
ID :5,UserName:shouzhang,Password:5645645hanyuan@foxmail.com45648255GuangzhoushiDianbian65465
ID :5,UserName:shouzhang,Password:5645645hanyuan@foxmail.com45648255GuangzhoushiDianbian65465
Hibernate: 
    select
        profile0_.id as id1_0_,
        user1_.id as id0_1_,
        profile0_.user_id as user2_1_0_,
        profile0_.email as email1_0_,
        profile0_.phone as phone1_0_,
        profile0_.mobile as mobile1_0_,
        profile0_.address as address1_0_,
        profile0_.postcode as postcode1_0_,
        user1_.username as username0_1_,
        user1_.password as password0_1_ 
    from
        users.profile profile0_ 
    inner join
        users.user user1_ 
            on profile0_.user_id=user1_.id
ID:1   Username: hongten   Email: hongtenzone@foxmail.com,   Address: Guangzhoushi
ID:2   Username: hanyuan   Email: hanyuan@foxmail.com,   Address: GuangzhoushiDianbian
ID:3   Username:Hongwei1231   Email: hanyuan@foxmail.com,   Address: GuangzhoushiDianbian
Hibernate: 
    select
        this_.id as id1_1_,
        this_.user_id as user2_1_1_,
        this_.email as email1_1_,
        this_.phone as phone1_1_,
        this_.mobile as mobile1_1_,
        this_.address as address1_1_,
        this_.postcode as postcode1_1_,
        user1_.id as id0_0_,
        user1_.username as username0_0_,
        user1_.password as password0_0_ 
    from
        users.profile this_ 
    inner join
        users.user user1_ 
            on this_.user_id=user1_.id
ID:1   Username: hongten   Email: hongtenzone@foxmail.com,   Address: Guangzhoushi
ID:2   Username: hanyuan   Email: hanyuan@foxmail.com,   Address: GuangzhoushiDianbian
ID:3   Username: Hongwei1231   Email: hanyuan@foxmail.com,   Address: GuangzhoushiDianbian
##################################################
Hibernate: 
    select
        this_.id as id1_1_,
        this_.user_id as user2_1_1_,
        this_.email as email1_1_,
        this_.phone as phone1_1_,
        this_.mobile as mobile1_1_,
        this_.address as address1_1_,
        this_.postcode as postcode1_1_,
        user2_.id as id0_0_,
        user2_.username as username0_0_,
        user2_.password as password0_0_ 
    from
        users.profile this_ 
    left outer join
        users.user user2_ 
            on this_.user_id=user2_.id
ID:1   Username: hongten   Email: hongtenzone@foxmail.com,   Address: Guangzhoushi
ID:2   Username: hanyuan   Email: hanyuan@foxmail.com,   Address: GuangzhoushiDianbian
ID:3   Username: 洪伟1231   Email: hanyuan@foxmail.com,   Address: GuangzhoushiDianbian
Hibernate: 
    select
        profile0_.id as id1_0_,
        user1_.id as id0_1_,
        profile0_.user_id as user2_1_0_,
        profile0_.email as email1_0_,
        profile0_.phone as phone1_0_,
        profile0_.mobile as mobile1_0_,
        profile0_.address as address1_0_,
        profile0_.postcode as postcode1_0_,
        user1_.username as username0_1_,
        user1_.password as password0_1_ 
    from
        users.profile profile0_ 
    left outer join
        users.user user1_ 
            on profile0_.user_id=user1_.id 
    order by
        profile0_.user_id
ID:1   Username: hongten   Email: hongtenzone@foxmail.com,   Address: Guangzhoushi
ID:2   Username: hanyuan   Email: hanyuan@foxmail.com,   Address: GuangzhoushiDianbian
ID:3   Username: 洪伟1231   Email: hanyuan@foxmail.com,   Address: GuangzhoushiDianbian
-------------------------------------
Hibernate: 
    select
        user0_.id as id0_0_,
        profiles1_.id as id1_1_,
        user0_.username as username0_0_,
        user0_.password as password0_0_,
        profiles1_.user_id as user2_1_1_,
        profiles1_.email as email1_1_,
        profiles1_.phone as phone1_1_,
        profiles1_.mobile as mobile1_1_,
        profiles1_.address as address1_1_,
        profiles1_.postcode as postcode1_1_,
        profiles1_.user_id as user2_0__,
        profiles1_.id as id0__ 
    from
        users.user user0_ 
    left outer join
        users.profile profiles1_ 
            on user0_.id=profiles1_.user_id
1hongten[com.b510.example.Profile@14eaec9]
2hanyuan[com.b510.example.Profile@569c60]
3Hongwei1231[com.b510.example.Profile@d67067]
4mingliu[]
5shouzhang[]
Hibernate: 
    select
        user0_.id as id0_,
        user0_.username as username0_,
        user0_.password as password0_ 
    from
        users.user user0_ 
    right outer join
        users.profile profiles1_ 
            on user0_.id=profiles1_.user_id 
    order by
        user0_.id
Hibernate: 
    select
        profiles0_.user_id as user2_1_,
        profiles0_.id as id1_,
        profiles0_.id as id1_0_,
        profiles0_.user_id as user2_1_0_,
        profiles0_.email as email1_0_,
        profiles0_.phone as phone1_0_,
        profiles0_.mobile as mobile1_0_,
        profiles0_.address as address1_0_,
        profiles0_.postcode as postcode1_0_ 
    from
        users.profile profiles0_ 
    where
        profiles0_.user_id=?
1hongten[com.b510.example.Profile@10c0f66]
Hibernate: 
    select
        profiles0_.user_id as user2_1_,
        profiles0_.id as id1_,
        profiles0_.id as id1_0_,
        profiles0_.user_id as user2_1_0_,
        profiles0_.email as email1_0_,
        profiles0_.phone as phone1_0_,
        profiles0_.mobile as mobile1_0_,
        profiles0_.address as address1_0_,
        profiles0_.postcode as postcode1_0_ 
    from
        users.profile profiles0_ 
    where
        profiles0_.user_id=?
2hanyuan[com.b510.example.Profile@e265d0]
Hibernate: 
    select
        profiles0_.user_id as user2_1_,
        profiles0_.id as id1_,
        profiles0_.id as id1_0_,
        profiles0_.user_id as user2_1_0_,
        profiles0_.email as email1_0_,
        profiles0_.phone as phone1_0_,
        profiles0_.mobile as mobile1_0_,
        profiles0_.address as address1_0_,
        profiles0_.postcode as postcode1_0_ 
    from
        users.profile profiles0_ 
    where
        profiles0_.user_id=?
3Hongwei1231[com.b510.example.Profile@8997d1]
分享到:
评论

相关推荐

    全面解析HQL语句 非常详细直接的HQL语句的功能介绍

    标题:“全面解析HQL语句 非常详细直接的HQL语句的功能介绍” 描述:“非常详细直接实用的HQL语句的功能介绍看过的人保准都说好” 本篇文章将深入探讨HQL(Hibernate Query Language)的核心功能及其在数据查询...

    hql语句大全hql语句大全

    ### HQL语句详解:精通Hibernate查询语言 #### 引言 HQL(Hibernate Query Language)是Hibernate框架中用于执行数据库操作的一种强大的查询语言。它提供了面向对象的语法,允许开发人员以一种接近于编程语言的方式...

    HQL语句的语法

    HQL语句的语法结构与SQL相似,但更注重对象和类的概念。以下将详细介绍HQL语句的几个关键部分: 1. **from 子句**:这是HQL查询的起点,用于指定要查询的持久化类。例如,`from Person as p`表示从`Person`类中选择...

    Hibernate框架]Hql语句in中带参数的写法

    在HQL语句中,使用in关键字可以实现集合参数的传递,例如: ```java String hql = "FROM Login login WHERE login.id in (:ids)"; ``` 其中,`:ids`是参数的名称,需要在map中进行设置。 二、setParameter方法的...

    常用的hql语句用法解析

    本文将深入解析HQL语句的常见用法。 1. 大小写敏感性 HQL对Java类和属性的名称是大小写敏感的,但在关键字和表名方面,除了类名和属性名之外,HQL不区分大小写。因此,`SeLeCT`、`sELEct`和`SELECT`被视为相同,但`...

    hql语句语法详解hql语句

    ### HQL语句语法详解 HQL(Hibernate Query Language)是一种面向对象的查询语言,它提供了灵活而强大的机制来查询数据库中的数据,并将其映射到Java对象上。本篇文章将根据给定的信息深入探讨HQL的基本语法结构...

    常用的HQL语句下载

    以下是一些常用HQL语句的使用与说明: 1. **HQL更新语句**: 更新操作允许您修改数据库中的对象属性。在示例中,第4行的HQL语句`update PhUser set realName=?`用于更新`PhUser`表中所有记录的`realName`字段。第5...

    HQL语句详解Select/update/deletefromwhere...

    ### HQL语句详解:Select/update/delete from where... 在探讨HQL(Hibernate Query Language)时,我们首先要了解它是一种用于Hibernate框架中的查询语言,其语法结构与标准SQL查询语言非常相似,但又针对对象关系...

    hql基础语句

    本教程将深入讲解HQL的基础语句,包括ID生成策略、集合参数传递以及不同的传参方式。 ### 1. ID生成策略 在Hibernate中,实体类的主键(ID)生成策略是关键部分,它决定了如何为新记录分配唯一标识。以下是几种...

    Hibernate-HQL语句多对多写法

    "Hibernate-HQL语句多对多写法" Hibernate 是一个流行的 Java 持久层框架,它提供了强大的对象关系映射(ORM)功能,使得开发者可以方便地与数据库交互。但是,在使用 Hibernate 时,我们经常会遇到多对多关系的...

    hql语句经典教程

    【HQL语句经典教程】 Hibernate Query Language(HQL)是Hibernate框架提供的面向对象的查询语言,它在外观上类似于SQL,但具有显著的面向对象特性,如支持继承、多态和关联。本教程将深入讲解HQL的基本概念、用法...

    Hql语句注意事项总结

    一种方法是动态构建Hql语句,将数组元素拼接成一个逗号分隔的字符串,然后在`in`子句中使用这个字符串。例如,`id in ('1','2','3')`。另一种方法是使用Hibernate的参数绑定功能,直接将数组作为参数传递,Hibernate...

    hibernate的hql语句

    【hibernate的HQL语句】是Hibernate框架中用于操作数据库的重要组成部分,它是一种面向对象的查询语言,类似于SQL,但更加强调对象的概念。HQL能够处理复杂的对象关系,如继承、多态和关联,使得在进行SSH(Spring、...

    hql语句的学习,很有用的东西

    本篇文章将深入探讨HQL语句的学习及其在Hibernate中的应用。 首先,HQL语句的核心特性是它的面向对象性。与SQL不同,HQL直接操作对象和实体,这使得代码更易于理解和维护。例如,如果你想从数据库中获取所有User...

    HQL语句的用法

    HQL还支持排序(order by)、分页(first result和max results)、类型转换(cast)、集合操作(in、any、all、some)等高级特性,使得它能够处理复杂的查询需求。 总之,HQL作为Hibernate的一部分,提供了强大的...

    HQL语句(结合实例)

    ### HQL语句详解 #### 一、HQL概述 HQL(Hibernate Query Language),即Hibernate查询语言,是一种面向对象的查询语言。它类似于SQL语言,但与SQL不同的是,HQL主要关注于对象的获取,而非直接进行数据库层面的...

    hibernate 中HQL语句查询学习笔记

    ### Hibernate中HQL语句查询学习笔记 #### HQL基础 **HQL**(Hibernate Query Language)是Hibernate框架推荐使用的查询语言,它提供了一种面向对象的方式来查询数据库,支持多种复杂的查询操作,如继承、多态及...

    hql语句查询

    ### HQL语句查询知识点详解 #### 一、HQL简介 HQL(Hibernate Query Language)是Hibernate框架中用于查询数据的一种语言。它类似于SQL,但面向对象特性更明显,可以更加灵活地处理复杂的对象图关系。HQL支持基本的...

    HQL查询及语法

    3. **创建Query对象**:利用Session对象的`createQuery`方法,传入HQL语句创建Query实例。 4. **设置参数**:如果HQL语句中包含参数,需调用Query对象的`setXxx`方法为其赋值。 5. **执行查询并处理结果**:最后...

    强烈建议的HQL语法规则详解

    3. **创建Query对象**:将HQL语句传递给`Session`的`createQuery`方法,返回一个`Query`实例,该实例代表了你的查询。 4. **设置参数**:如果HQL中包含参数,如上面的例子中的`:eventTitle`,可以通过`Query`对象的`...

Global site tag (gtag.js) - Google Analytics