hibernate根据id查找

/**根据id查找*/

public static User1 query(String id) {
  User1 u = null;
  try {
   session = HibernateSessionFactory.getSession();
   Transaction tran = session.beginTransaction();
   u = (User1) session.get(User1.class, id);
   session.get(User1.class, id);//get()方法也会产生查询语句
   tran.commit();
  } catch (Exception e) {
   e.printStackTrace();
  } finally {
   HibernateSessionFactory.closeSession();
  }
  return u;
 }
 

你可能感兴趣的:(hibernate)