查询获得对象

根据主键直接获得对象:
customer = (Customer) sess.get(Customer.class, 1);

customer = (Customer) sess.load(Customer.class, 1);

使用SQL的实体查询
List users = (List<Customer>) sess.createSQLQuery("select * from CUSTOMER")
        .addEntity(Customer.class)
        .list();
Iterator it = users.iterator();
customer = (Customer) it.next();

使用HQL的查询(面向对象的查询)
List lt = sess.createQuery("select c from Customer c")
    .list();
users = (List<Customer>) lt;

posted @ 2012-01-29 13:19  lastren  阅读(150)  评论(0编辑  收藏  举报