关闭

Hibernate(JFIS)

514人阅读 评论(0) 收藏 举报
 
 
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();
                           
              }
}
 
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:436598次
    • 积分:5501
    • 等级:
    • 排名:第4798名
    • 原创:141篇
    • 转载:120篇
    • 译文:4篇
    • 评论:30条
    最新评论