怎么用hibernate的hql通过id查询单个对象并接收

2024-12-19 14:01:26
推荐回答(2个)
回答1:

public User query(int id){
String hql = "from User where id = ?";

User user = getHibernateTemplate().queryForObject( hql,new Object[]{id});
}

回答2:

Session session = HibernateSessionFactory.getSession();
Object obj = session.get(id);
session.close();
return obj;