zoukankan      html  css  js  c++  java
  • Hibernate- QBC离线查询

    package com.gordon.test;
    
    import java.util.List;
    
    import org.hibernate.Criteria;
    import org.hibernate.Session;
    import org.hibernate.Transaction;
    import org.hibernate.criterion.DetachedCriteria;
    import org.hibernate.criterion.Restrictions;
    import org.junit.Test;
    
    import com.gordon.domain.Book;
    import com.gordon.utils.HibernateUtil;
    
    /**
     * QBC查询
     * 
     * @author Administrator
     */
    public class TestQBCDemo2 {
    
    	/**
    	 * 离线查询 Hibernate: select this_.id as id1_0_0_, this_.name as name2_0_0_,
    	 * this_.price as price3_0_0_, this_.publisher_id as publishe4_0_0_ from
    	 * t_book this_ where this_.price<=? C语言程序设计 Photoshop图形图像处理
    	 * VisualBasic2015实践教程 生产微服务
    	 */
    	@Test
    	public void run() {
    		/**
    		 * 离线查询对象
    		 */
    		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Book.class);
    		detachedCriteria.add(Restrictions.le("price", 44.00));
    
    		/**
    		 * session
    		 */
    		Session currentSession = HibernateUtil.getCurrentSession();
    		Transaction transaction = currentSession.beginTransaction();
    
    		/**
    		 * 设置此离线对象要被哪个session执行
    		 */
    		Criteria executableCriteria = detachedCriteria.getExecutableCriteria(currentSession);
    
    		/**
    		 * 查询结果
    		 */
    		List<Book> list = executableCriteria.list();
    		for (Book book : list) {
    			System.out.println(book.getName());
    		}
    
    		transaction.commit();
    	}
    }
    
  • 相关阅读:
    js图片放大
    js编写点名器
    javascript中的math和随机数
    python中 __slots__
    python中 @property
    CentOS 6.5通过yum安装 MySQL-5.5
    linux下环境搭建
    oracle:ORA-01940无法删除当前已连接用户的解决方案
    不同版本apache(免安装)下部署Javaee多套项目
    使用poi处理excel
  • 原文地址:https://www.cnblogs.com/hfultrastrong/p/7423141.html
Copyright © 2011-2022 走看看