我想使用 Hibernate 从数据库中检索特定记录。我想要做的事情在函数下面注释了。
public List<Customer> showCustomer(long customerIdFromCustomerListPage)
throws Exception {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = null;
List<Customer> customerList = new ArrayList<Customer>();
try {
transaction = session.beginTransaction();
**//Select * from Customers where customerId="customerIdFromCustomerListPage"**
transaction.commit();
} catch (HibernateException e) {
transaction.rollback();
e.printStackTrace();
} finally {
session.close();
}
return customerList;
}
最佳答案
尝试这样的事情
public Customer getCustomer(Long customerIdFromCustomerListPage)
throws Exception {
Session session = HibernateUtil.getSessionFactory().openSession();
Customer customer = (Customer )session.get(Customer.class, customerIdFromCustomerListPage);
return customer ;
}
关于java - 使用 Hibernate 检索特定记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12909032/