查询获得对象
根据主键直接获得对象:
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;