码迷,mamicode.com
首页 > Web开发 > 详细

hibernate关于多对多映射和多对一的hql查询

时间:2018-06-21 00:06:06      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:list()   generated   多对多   water   ext   exception   term   ssi   get   

public void queryCustomerbymerchantId(){  
        SessionFactory sf = HibernateUtil.getSessionFactory();  
        Session session = sf.getCurrentSession();  
        Transaction ts = session.beginTransaction();  
        try {  
       Query query=session.createQuery("select c from Customer c join c.merchant m where m.mid=1");  
       List customer = query.list();  
       for(int i=0;i<customer.size();i++)  
       {  
        Customer customers =(Customer)customer.get(i);  
            System.out.println(i+"--"+customers);  
       }  
  
        ts.commit();      
          
    } catch (HibernateException e) {  
        // TODO Auto-generated catch block  
        if(ts != null)  
        {  
            ts.rollback();  
        }  
        e.printStackTrace();  
    }  
}  

  技术分享图片

public void queryCustomerbyOrderId(){  
        SessionFactory sf = HibernateUtil.getSessionFactory();  
        Session session = sf.getCurrentSession();  
        Transaction ts = session.beginTransaction();  
//      int n;  
//      Scanner sc=new Scanner(System.in);  
//      n=sc.nextInt();  
        try {  
       Query query=session.createQuery("select customer from Order o where  o.id=1" );  
       System.out.println(query);  
       List customer = query.list();     
       for(int i=0;i<customer.size();i++)  
       {  
        Customer customers =(Customer)customer.get(i);  
            System.out.println(i+"--"+customers);  
       }  
  
        ts.commit();      
          
    } catch (HibernateException e) {  
        // TODO Auto-generated catch block  
        if(ts != null)  
        {  
            ts.rollback();  
        }  
        e.printStackTrace();  
    }  
}  

  技术分享图片

hibernate关于多对多映射和多对一的hql查询

标签:list()   generated   多对多   water   ext   exception   term   ssi   get   

原文地址:https://www.cnblogs.com/acefeng/p/9206289.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!