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();
    	}
    }
    
  • 相关阅读:
    ECMAScript 6 基础入门
    软件历史版本存档及下载
    arduino 编程基础
    生活中的实验 —— 家庭电路
    电子元件 —— 继电器
    电与磁 —— 电磁铁
    windows cmd 命令行 —— 进程与服务
    计算机硬件、摄影设备、物质、材料英语
    DHCP服务器备份、还原、迁移
    SVN同步
  • 原文地址:https://www.cnblogs.com/hfultrastrong/p/7423141.html
Copyright © 2011-2022 走看看