日期:2014-05-17 浏览次数:20981 次
List<TGoods> list = null;
SessionFactory sf = null;
Session ses = null;
try {
Configuration cfg = new Configuration().configure();
ServiceRegistry sr = new ServiceRegistryBuilder().applySettings(
cfg.getProperties()).buildServiceRegistry();
sf = cfg.buildSessionFactory(sr);
ses = sf.openSession();
Criteria c = ses.createCriteria(TGoods.class);// Tuser.hbm.xml中定义的字段
list = c.list();
} catch (HibernateException e) {
System.out.println("hibernate exception");
e.printStackTrace();
return list;
} finally {
ses.close();
sf.close();
}
return list;