hibernate框架学习笔记10:HQL查询详解,hibernatehql

hibernate框架学习笔记10:HQL查询详解,hibernatehql

HQL语句中不可以出现与表有关的内容,而是对象的属性

实体类(注意配置文件):

奥门永利误乐域 1

package domain;

import java.util.HashSet;
import java.util.Set;

//客户实体
public class Customer {

    private Long cust_id;
    private String cust_name;
    private String cust_source;
    private String cust_industry;
    private String cust_level;
    private String cust_linkman;
    private String cust_phone;
    private String cust_mobile;
    //使用set集合,表达一对多关系
    private Set<LinkMan> linkMens = new HashSet<LinkMan>();

    public Set<LinkMan> getLinkMens() {
        return linkMens;
    }
    public void setLinkMens(Set<LinkMan> linkMens) {
        this.linkMens = linkMens;
    }
    public Long getCust_id() {
        return cust_id;
    }
    public void setCust_id(Long cust_id) {
        this.cust_id = cust_id;
    }
    public String getCust_name() {
        return cust_name;
    }
    public void setCust_name(String cust_name) {
        this.cust_name = cust_name;
    }
    public String getCust_source() {
        return cust_source;
    }
    public void setCust_source(String cust_source) {
        this.cust_source = cust_source;
    }
    public String getCust_industry() {
        return cust_industry;
    }
    public void setCust_industry(String cust_industry) {
        this.cust_industry = cust_industry;
    }
    public String getCust_level() {
        return cust_level;
    }
    public void setCust_level(String cust_level) {
        this.cust_level = cust_level;
    }
    public String getCust_linkman() {
        return cust_linkman;
    }
    public void setCust_linkman(String cust_linkman) {
        this.cust_linkman = cust_linkman;
    }
    public String getCust_phone() {
        return cust_phone;
    }
    public void setCust_phone(String cust_phone) {
        this.cust_phone = cust_phone;
    }
    public String getCust_mobile() {
        return cust_mobile;
    }
    public void setCust_mobile(String cust_mobile) {
        this.cust_mobile = cust_mobile;
    }
    @Override
    public String toString() {
        return "Customer [cust_id=" + cust_id + ", cust_name=" + cust_name + "]";
    }
}

View Code

 

抽取工具类:

奥门永利误乐域 2

package utils;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtils {
    private static SessionFactory sf;

    static{
        //1 创建,调用空参构造
        Configuration conf = new Configuration().configure();
        //2 根据配置信息,创建 SessionFactory对象
         sf = conf.buildSessionFactory();
    }

    //获得session => 获得全新session
    public static Session openSession(){
                //3 获得session
                Session session = sf.openSession();

                return session;

    }
    //获得session => 获得与线程绑定的session
    public static Session getCurrentSession(){
        //3 获得session
        Session session = sf.getCurrentSession();

        return session;
    }    
}

View Code

 

测试类:

基本语法:

package hql;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;

import domain.Customer;
import utils.HibernateUtils;

//学习HQL语法
public class Demo {

    //基本语法
    @Test
    public void fun1(){
        Session session = HibernateUtils.openSession();
        Transaction tx = session.beginTransaction();
        //----------------------------------------------------
        String hql = " from  domain.Customer ";//完整写法
        String hql2 = " from  Customer "; //简单写法
        String hql3 = " from java.lang.Object "; //查询所有Object对象,即所有对象

        Query query = session.createQuery(hql);

        List list = query.list();

        System.out.println(list);
        //----------------------------------------------------
        tx.commit();
        session.close();

    }


    @Test
    //排序
    public void fun2(){
        Session session = HibernateUtils.openSession();
        Transaction tx = session.beginTransaction();
        //----------------------------------------------------
        String hql1 = " from  domain.Customer order by cust_id asc ";//完整写法升序
        String hql2 = " from  domain.Customer order by cust_id desc ";//完整写法降序

        Query query = session.createQuery(hql2);

        List list = query.list();

        System.out.println(list);
        //----------------------------------------------------
        tx.commit();
        session.close();

    }

    @Test
    //条件查询
    public void fun3(){
        Session session = HibernateUtils.openSession();
        Transaction tx = session.beginTransaction();
        //----------------------------------------------------
        String hql1 = " from  domain.Customer where cust_id =? ";//?按所有传值
        String hql2 = " from  domain.Customer where cust_id = :id ";//:按名称传值

        Query query = session.createQuery(hql2);

        //query.setParameter(0, 5l);
        query.setParameter("id", 5l);


        List list = query.list();

        System.out.println(list);
        //----------------------------------------------------
        tx.commit();
        session.close();

    }

    @Test
    //分页查询
    public void fun4(){
        Session session = HibernateUtils.openSession();
        Transaction tx = session.beginTransaction();
        //----------------------------------------------------
        String hql1 = " from  domain.Customer  ";//完整写法

        Query query = session.createQuery(hql1);

        //类似SQL中的limit ?,?
        // (当前页数-1)*每页条数
        query.setFirstResult(0);
        query.setMaxResults(2);

        List list = query.list();

        System.out.println(list);
        //----------------------------------------------------
        tx.commit();
        session.close();

    }

    @Test
    //统计查询
    //count    计数
    //sum     求和
    //avg    平均数
    //max
    //min
    public void fun5(){
        Session session = HibernateUtils.openSession();
        Transaction tx = session.beginTransaction();
        //----------------------------------------------------
        String hql1 = " select count(*) from  domain.Customer  ";
        String hql2 = " select sum(cust_id) from  domain.Customer  ";
        String hql3 = " select avg(cust_id) from  domain.Customer  ";
        String hql4 = " select max(cust_id) from  domain.Customer  ";
        String hql5 = " select min(cust_id) from  domain.Customer  ";

        Query query = session.createQuery(hql3);

        Number number  = (Number) query.uniqueResult();

        System.out.println(number);
        //----------------------------------------------------
        tx.commit();
        session.close();

    }


    @Test
    //投影查询
    //查询对象某一个属性
    public void fun6(){
        Session session = HibernateUtils.openSession();
        Transaction tx = session.beginTransaction();
        //----------------------------------------------------
        String hql1 = " select cust_name from  domain.Customer  ";
        String hql2 = " select cust_name,cust_id from  domain.Customer  ";
        String hql3 = " select new Customer(cust_id,cust_name) from  domain.Customer  ";
        //如果实体类有相应构造方法,也可以执行

        Query query = session.createQuery(hql2);

        List list = query.list();

        System.out.println(list);

        //----------------------------------------------------
        tx.commit();
        session.close();

    }
}

 

 

多表查询:

再创建一个实体类:

奥门永利误乐域 3

package domain;

//联系人实体
public class LinkMan {
    private Long lkm_id;
    private Character lkm_gender;
    private String lkm_name;
    private String lkm_phone;
    private String lkm_email;
    private String lkm_qq;
    private String lkm_mobile;
    private String lkm_memo;
    private String lkm_position;

    // 表达多对一关系
    private Customer customer;

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public Long getLkm_id() {
        return lkm_id;
    }

    public void setLkm_id(Long lkm_id) {
        this.lkm_id = lkm_id;
    }

    public Character getLkm_gender() {
        return lkm_gender;
    }

    public void setLkm_gender(Character lkm_gender) {
        this.lkm_gender = lkm_gender;
    }

    public String getLkm_name() {
        return lkm_name;
    }

    public void setLkm_name(String lkm_name) {
        this.lkm_name = lkm_name;
    }

    public String getLkm_phone() {
        return lkm_phone;
    }

    public void setLkm_phone(String lkm_phone) {
        this.lkm_phone = lkm_phone;
    }

    public String getLkm_email() {
        return lkm_email;
    }

    public void setLkm_email(String lkm_email) {
        this.lkm_email = lkm_email;
    }

    public String getLkm_qq() {
        return lkm_qq;
    }

    public void setLkm_qq(String lkm_qq) {
        this.lkm_qq = lkm_qq;
    }

    public String getLkm_mobile() {
        return lkm_mobile;
    }

    public void setLkm_mobile(String lkm_mobile) {
        this.lkm_mobile = lkm_mobile;
    }

    public String getLkm_memo() {
        return lkm_memo;
    }

    public void setLkm_memo(String lkm_memo) {
        this.lkm_memo = lkm_memo;
    }

    public String getLkm_position() {
        return lkm_position;
    }

    public void setLkm_position(String lkm_position) {
        this.lkm_position = lkm_position;
    }

}

View Code

 

测试类:

package hql;

import java.util.Arrays;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;

import domain.Customer;
import utils.HibernateUtils;

//学习HQL语法(不常用) - 多表查询语法
public class Demo2 {
    //原生SQL中:
    // 交叉连接-笛卡尔积(避免)
//        select * from A,B 
    // 内连接
//        |-隐式内连接
//            select * from A,B  where b.aid = a.id
//        |-显式内连接
//            select * from A inner join B on b.aid = a.id
    // 外连接
//        |- 左外
//            select * from A left [outer] join B on b.aid = a.id
//        |- 右外
//            select * from A right [outer] join B on b.aid = a.id
//---------------------------------------------------------------------
//HQL的多表查询
        //内连接(迫切)
        //外连接
//            |-左外(迫切)
//            |-右外(迫切)

    @Test
    //HQL 内连接 => 将连接的两端对象分别返回.放到数组中.
    public void fun1(){
        Session session = HibernateUtils.openSession();
        Transaction tx = session.beginTransaction();
        //----------------------------------------------------
        String hql = " from Customer c inner join c.linkMens ";
        //c相当于别名
        Query query = session.createQuery(hql);

        List<Object[]> list = query.list();

        for(Object[] arr : list){
            System.out.println(Arrays.toString(arr));
        }
        //----------------------------------------------------
        tx.commit();
        session.close();

    }

    @Test
    //HQL 迫切内连接 => 帮我们进行封装.返回值就是一个对象
    public void fun2(){
        Session session = HibernateUtils.openSession();
        Transaction tx = session.beginTransaction();
        //----------------------------------------------------
        String hql = " from Customer c inner join fetch c.linkMens ";

        Query query = session.createQuery(hql);

        List<Customer> list = query.list();

        System.out.println(list);
        //----------------------------------------------------
        tx.commit();
        session.close();

    }

    @Test
    //HQL 左外连接 => 将连接的两端对象分别返回.放到数组中.
    public void fun3(){
        Session session = HibernateUtils.openSession();
        Transaction tx = session.beginTransaction();
        //----------------------------------------------------
        String hql = " from Customer c left join c.linkMens ";

        Query query = session.createQuery(hql);

        List<Object[]> list = query.list();

        for(Object[] arr : list){
            System.out.println(Arrays.toString(arr));
        }
        //----------------------------------------------------
        tx.commit();
        session.close();

    }
    @Test
    //HQL 右外连接 => 将连接的两端对象分别返回.放到数组中.
    public void fun4(){
        Session session = HibernateUtils.openSession();
        Transaction tx = session.beginTransaction();
        //----------------------------------------------------
        String hql = " from Customer c right join c.linkMens ";

        Query query = session.createQuery(hql);

        List<Object[]> list = query.list();

        for(Object[] arr : list){
            System.out.println(Arrays.toString(arr));
        }
        //----------------------------------------------------
        tx.commit();
        session.close();

    }

}

 

补上内连接与外连接区别:

奥门永利误乐域 4

http://www.bkjia.com/Javabc/1305337.htmlwww.bkjia.comtruehttp://www.bkjia.com/Javabc/1305337.htmlTechArticlehibernate框架学习笔记10:HQL查询详解,hibernatehql
HQL语句中不可以出现与表有关的内容,而是对象的属性
实体类(注意配置文件): package…

奥门永利误乐域 5

hibernate

1.hibernate 查询方式


    1. 对象导航查询
      一个对象关联了另一个对象,并且两者是一对多的关系,那么通过一个(一方)对象就可以找到另外一个(多方)对象。例如:由一个班级就可以找到班上所有的学生,这种通过班级对象找到学生对象的查询方式就叫做对象导航查询。
    1. OID 查询
      又称对象唯一标识符查询。根据对象属性中的唯一标识值来查询这个对象,session
      的 get() 方法还有下面说到的 load() 方法,都是 OID 的查询方式。
    1. HQL 查询
      使用 Query 对象调用相关的方法来做查询,需要写相关的hql语句,这是
      hibernate 提供的查询语言,hql 语句中写的是实体类和属性,而 sql
      语句中写的是数据表和字段。
    1. QBC 查询
      使用 Criteria
      对象调用相关的方法做查询,但是不需要写语句,调用的是方法,操作的也是实体类和属性。
    1. SQL 查询
      使用 SQLQuery 对象写普通的 sql
      语句来做查询,但由于数据库的不同,sql
      语句也有所不同,所以一般不使用这种查询方式。但如果需要底层数据库的
      SQL 方言查询时,还是可以使用这种方式的。hibernate 种也封装了 SQL
      查询的对象 SQLQuery。

2.基本代码


下面的例子也是基于班级和学生一对多关系说明的。

2.1 实体类代码

  • 学生实体类

package cc.wenshixin.entity;

public class Student {
    private Integer id; // 学号
    private String name; // 姓名
    private Integer age; // 年龄

    private Banji banji; // 所属班级

    public Student() {

    }

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    //get,set方法在此省略,必须要写的
}
  • 班级实体类

package cc.wenshixin.entity;

import java.util.HashSet;
import java.util.Set;

public class Banji {
    private Integer id; //编号
    private String name; //名称

    private Set<Student> setStudent = new HashSet<Student>(); //班级里的学生

    public Banji() {

    }

    public Banji(String name) {
        this.name = name;
    }
    //get,set方法在此省略,必须要写的
}
  • 工具类

package cc.wenshixin.utility;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtility {
    private static Configuration cfg = null;
    private static SessionFactory sessionFactory = null;

    static{
        cfg = new Configuration().configure();
        sessionFactory = cfg.buildSessionFactory();
    }

    //获得sessionFactory对象的方法
    public static SessionFactory getSessionFactory()
    {
        return sessionFactory;
    }   
}

2.2 映射文件

  • 学生实体类映射文件

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="cc.wenshixin.entity.Student" table="student">
        <id name="id" type="java.lang.Integer" column="sid">
            <generator class="native" />
        </id>
        <property name="name" type="java.lang.String" column="sname">
        </property>
        <property name="age" type="java.lang.Integer" column="age">
        </property>
        <many-to-one name="banji" class="cc.wenshixin.entity.Banji" column="sbid">
        </many-to-one>
    </class>
</hibernate-mapping>
  • 班级实体类映射文件

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="cc.wenshixin.entity.Banji" table="banji">
        <id name="id" type="java.lang.Integer" column="bid">
            <generator class="native" />
        </id>
        <property name="name" type="java.lang.String" column="bname">
        </property>
        <set name="setStudent" table="student" cascade="save-update">
            <key column="sbid">
            </key>
            <one-to-many class="cc.wenshixin.entity.Student" />
        </set>
    </class>
</hibernate-mapping>
  • 核心配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
      <!-- 数据库信息配置 -->
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="connection.url">jdbc:mysql://localhost:3306/数据库名?useUnicode=true&characterEncoding=UTF-8</property>
      <property name="connection.username">用户名</property>
      <property name="connection.password">密码</property>

      <!-- hibernate功能选择 -->
      <property name="show_sql">true</property>
      <property name="format_sql">true</property>
      <property name="hbm2ddl.auto">update</property>
      <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>

      <!-- 加载映射文件 -->
      <mapping resource="cc/wenshixin/entity/Student.hbm.xml"/>
      <mapping resource="cc/wenshixin/entity/Banji.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

2.3 数据初始化

    @Test
    //初始化数据
    public void initData()
    {
        SessionFactory sessionFactory = null;
        Session session = null;
        Transaction tx = null;
        try{
            sessionFactory = HibernateUtility.getSessionFactory();
            session = sessionFactory.openSession();
            tx = session.beginTransaction();

            //插入数据
            Banji banji1 = new Banji("计科一班");
            Banji banji2 = new Banji("计科二班");
            Banji banji3 = new Banji("计科三班");
            Banji banji4 = new Banji("计科四班");

            Student student1 = new Student("小明", 20);
            Student student2 = new Student("小红", 19);
            Student student3 = new Student("小智", 21);
            Student student4 = new Student("小张", 20);
            Student student5 = new Student("小李", 19);
            Student student6 = new Student("老王", 23);
            Student student7 = new Student("小魏", 20);

            banji1.getSetStudent().add(student1);
            banji1.getSetStudent().add(student3);
            banji2.getSetStudent().add(student2);
            banji2.getSetStudent().add(student5);
            banji2.getSetStudent().add(student4);
            banji3.getSetStudent().add(student6);
            banji4.getSetStudent().add(student7);

            session.save(banji1);
            session.save(banji2);
            session.save(banji3);
            session.save(banji4);

            tx.commit();
        }catch (Exception e) {
            e.printStackTrace();
            tx.rollback();
        }finally {
            session.close();
            sessionFactory.close();
        }
    }

2.4 对象导航查询测试

    @Test
    //对象导航查询方式
    public void test()
    {
        SessionFactory sessionFactory = null;
        Session session = null;
        Transaction tx = null;
        try{
            sessionFactory = HibernateUtility.getSessionFactory();
            session = sessionFactory.openSession();
            tx = session.beginTransaction();

            Banji banji = session.get(Banji.class, 2);
            Set<Student> setStudent = banji.getSetStudent();

            System.out.println(setStudent.size());
            for (Student student : setStudent) {
    System.out.println(student.getId()+":"+student.getName()+":"+student.getAge());
            }

            tx.commit();
        }catch (Exception e) {
            e.printStackTrace();
            tx.rollback();
        }finally {
            session.close();
            sessionFactory.close();
        }
    }

3.HQL 查询


常用的 hql 语句(关键字大小写都可以的):

    1. 查询所有:
      from 实体类名称
    1. 条件查询(使用 AS 关键词设置别名):
      奥门永利误乐域,from 实体类名称 as 别名 where 别名.属性名称=?
      from 实体类名称 as 别名 where 别名.属性名称=? and
      别名.属性名称=?
      from 实体类名称 as 别名 where 别名.属性名称 like ?
    1. 排序查询:
      from 实体类名称 as 别名 order by 别名.属性名称 asc/desc
    1. 分页查询:
      通过调用方法来实现,设置开始位置
      query.setFirstResult(0);,设置每页记录数
      query.setMaxResults(3);
  • 5.投影查询:
    在投影查询中才会用到 SELECT
    关键字,在前面的查询中是用不到的,并且不能使用 * 号。
    select 属性名称 from 实体类名称

  • 6.函数查询:
    在HQL中也是可以使用 sql
    函数的,count()函数计算数量,sum()函数求和,avg()函数计算平均值,max()函数计算最大值,min()函数计算最小值。

hql语句查询步骤:

    1. 创建 Query 对象,写 hql 语句
    1. 调用 query 对象里面的方法得到结果

3.1 查询所有

    @Test
    //HQL查询表中所有数据
    public void testQueryAll()
    {
        SessionFactory sessionFactory = null;
        Session session = null;
        Transaction tx = null;
        try{
            sessionFactory = HibernateUtility.getSessionFactory();
            session = sessionFactory.openSession();
            tx = session.beginTransaction();

            Query<Banji> query = session.createQuery("FROM Banji");

            List<Banji> list = query.list();

            for(Banji banji:list)
            {
                System.out.println(banji.getId()+":"+banji.getName());
            }

            tx.commit();
        }catch (Exception e) {
            e.printStackTrace();
            tx.rollback();
        }finally {
            session.close();
            sessionFactory.close();
        }
    }

3.2 条件查询

    @Test
    //HQL带条件的查询
    public void testQueryWhere1()
    {
        SessionFactory sessionFactory = null;
        Session session = null;
        Transaction tx = null;
        try{
            sessionFactory = HibernateUtility.getSessionFactory();
            session = sessionFactory.openSession();
            tx = session.beginTransaction();

            Query<Banji> query = session.createQuery("FROM Banji AS banji WHERE banji.id=?");
            query.setParameter(0, 2);

            List<Banji> list = query.list();

            for(Banji banji:list)
            {
                System.out.println(banji.getId()+":"+banji.getName());
            }

            tx.commit();
        }catch (Exception e) {
            e.printStackTrace();
            tx.rollback();
        }finally {
            session.close();
            sessionFactory.close();
        }
    }

    @Test
    //模糊条件查询
    public void testQueryWhere2()
    {
        SessionFactory sessionFactory = null;
        Session session = null;
        Transaction tx = null;
        try{
            sessionFactory = HibernateUtility.getSessionFactory();
            session = sessionFactory.openSession();
            tx = session.beginTransaction();

            Query<Banji> query = session.createQuery("FROM Banji AS banji WHERE banji.name LIKE ?");
            query.setParameter(0, "%计科%");

            List<Banji> list = query.list();

            for(Banji banji:list)
            {
                System.out.println(banji.getId()+":"+banji.getName());
            }

            tx.commit();
        }catch (Exception e) {
            e.printStackTrace();
            tx.rollback();
        }finally {
            session.close();
            sessionFactory.close();
        }
    }

3.3 排序查询

    @Test
    //排序查询
    public void testQueryOrder()
    {
        SessionFactory sessionFactory = null;
        Session session = null;
        Transaction tx = null;
        try{
            sessionFactory = HibernateUtility.getSessionFactory();
            session = sessionFactory.openSession();
            tx = session.beginTransaction();

            Query<Banji> query = session.createQuery("FROM Banji AS banji ORDER BY banji.id DESC");

            List<Banji> list = query.list();

            for(Banji banji:list)
            {
                System.out.println(banji.getId()+":"+banji.getName());
            }

            tx.commit();
        }catch (Exception e) {
            e.printStackTrace();
            tx.rollback();
        }finally {
            session.close();
            sessionFactory.close();
        }
    }

3.4 分页查询

    @Test
    //分页查询
    public void testQueryPage()
    {
        SessionFactory sessionFactory = null;
        Session session = null;
        Transaction tx = null;
        try{
            sessionFactory = HibernateUtility.getSessionFactory();
            session = sessionFactory.openSession();
            tx = session.beginTransaction();

            Query<Student> query = session.createQuery("FROM Student");

            query.setFirstResult(2);
            query.setMaxResults(3);

            List<Student> list = query.list();

            for(Student student : list)
            {
                System.out.println(student.getId()+":"+student.getName()+":"+student.getAge());
            }

            tx.commit();
        }catch (Exception e) {
            e.printStackTrace();
            tx.rollback();
        }finally {
            session.close();
            sessionFactory.close();
        }
    }

3.5 投影查询

听起来很高大上,其实就是查询数据表中的某一列。。。

@Test
    //投影查询
    public void testQueryShade()
    {
        SessionFactory sessionFactory = null;
        Session session = null;
        Transaction tx = null;
        try{
            sessionFactory = HibernateUtility.getSessionFactory();
            session = sessionFactory.openSession();
            tx = session.beginTransaction();

            //注意返回的结果是一个object类型,而不是一个实体类的类型
            Query<Object> query = session.createQuery("SELECT name FROM Student");

            List<Object> list = query.list();

            for(Object object : list)
            {
                System.out.println(object);
            }

            tx.commit();
        }catch (Exception e) {
            e.printStackTrace();
            tx.rollback();
        }finally {
            session.close();
            sessionFactory.close();
        }
    }

发表评论

电子邮件地址不会被公开。 必填项已用*标注