java code: Session session=sessionFactory.openSession(); User user1=(User)session.createQuery("from User u where u.id=1").uniqueResult();
public static User QueryById(int id) {
Session session = HibernateSessionFactory.getSession();
User user = (User) session.get(user.User.class, id);
return user;
}