1

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;

}
4

1 に答える 1

1

このようなことを試してください

 public Customer getCustomer(Long customerIdFromCustomerListPage)
    throws Exception {

      Session session = HibernateUtil.getSessionFactory().openSession();
      Customer customer = (Customer )session.get(Customer.class, customerIdFromCustomerListPage); 
      return customer ;

}
于 2012-10-16T07:25:05.790 に答える