zoukankan      html  css  js  c++  java
  • 【Hibernate 多表查询】

    HibernateManyTable

    public class HibernateManyTable {
        
        //演示hql左连接查询
        @Test
        public void testSelect12() {
            SessionFactory sessionFactory = null;
            Session session = null;
            Transaction tx = null;
            try {
                sessionFactory = HibernateUtils.getSessionFactory();
                session = sessionFactory.openSession();
                tx = session.beginTransaction();
                
                //1 创建query对象
                Query query = session.createQuery("from Customer c left outer join fetch c.setLinkMan");
                
                
                List list = query.list();
                
                
                tx.commit();
            }catch(Exception e) {
                e.printStackTrace();
                tx.rollback();
            }finally {
                session.close();
                sessionFactory.close();
            }
        }
        
        //演示hql内连接查询
        @Test
        public void testSelect1() {
            SessionFactory sessionFactory = null;
            Session session = null;
            Transaction tx = null;
            try {
                sessionFactory = HibernateUtils.getSessionFactory();
                session = sessionFactory.openSession();
                tx = session.beginTransaction();
                
                //1 创建query对象
                Query query = session.createQuery("from Customer c inner join c.setLinkMan");
                
                List list = query.list();
                
                
                tx.commit();
            }catch(Exception e) {
                e.printStackTrace();
                tx.rollback();
            }finally {
                session.close();
                sessionFactory.close();
            }
        }
    }
  • 相关阅读:
    [转载]MATLAB 图像处理命令
    html Window与document区别(轉)
    ICMP数据包结构(转)
    CString,string,char*之间的转换(转)
    word或dword区别
    VS2010 皮肤扩展
    Unicode _T和L和_TXET
    转:git 的常用命令
    git fetch 和 git pull 的区别
    mac git 命令自动补全
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/12293253.html
Copyright © 2011-2022 走看看