Hibernate(JFIS)

 
 
Hibernate中的一个DAO
package com.bean;
 
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
 
public class CustomersDAO {
 
              Session session = HibernateSessionFactory.getSession();
              public List customer_list() {
                            Transaction t = session.beginTransaction();
                            Query query = session.createQuery("from com.bean.Customers");
                            List list = query.list();
                            t.commit();
                            session.close();
                            return list;
              }
             
                            public List customerOrderList(Integer id){
                             Transaction t = session.beginTransaction();
                             Query query = session.createQuery("from com.bean.Orders where customers = ?");
                             query.setInteger(0, id);
                             List list = query.list();
                             t.commit();
                             session.close();
                             return list;
              }
             
              public void delete(Integer id){
                            Transaction t = session.beginTransaction();
                            Orders o = new Orders();
                            o.setId(id);
                            session.delete(o);
                            t.commit();
                            session.close();
              }
             
              public void order_new(Customers customers, String orderNumber){
                            Transaction t = session.beginTransaction();
                            Orders o = new Orders();
                           
                            o.setCustomers(customers);
                            o.setId(customers.getId());
                            o.setOrderNumber(orderNumber);
                            session.save(o);
                            t.commit();
                            session.close();
              }
                                          public void order_update(Integer id, String orderNumber){
                            Transaction t = session.beginTransaction();
                           
        Query query = session.createQuery("update com.bean.Orders set orderNumber=? where id=?");
                            query.setString(0, orderNumber);
                  query.setInteger(1, id);
                            query.executeUpdate();
        t.commit();
                            session.close();
                           
              }
}
 
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wyyl1/article/details/1788293
个人分类: 在西安健飞学到的
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭