hibernate查询所有的记录

/**
  * 查询所有的记录
  */
 public static List selectAll() {
  List list = null;
  try {
   session = HibernateSessionFactory.getSession();
   Transaction tran = session.beginTransaction();
   Query q = session.createQuery("from User1");
   list = q.list();
   tran.commit();
  } catch (Exception e) {
   e.printStackTrace();
  } finally {
   HibernateSessionFactory.closeSession();
  }
  return list;
 } 

你可能感兴趣的:(hibernate)