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();
    	}
    }
    
  • 相关阅读:
    Linux系统-命令行快捷键
    Golang理解-Context包
    Golang理解-垃圾回收机制
    Linux系统-Systemd资源控制
    Linux系统-"cannot access Input/output error"
    Linux系统-ntpdate时间同步报错
    Golang理解-数组和切片
    Golang理解-位运算
    Golang理解-指针
    Maven配置,使用IntelliJ IDEA和Maven创建Java Web项目
  • 原文地址:https://www.cnblogs.com/hfultrastrong/p/7423141.html
Copyright © 2011-2022 走看看