我想使用Hibernate從數據庫檢索特定記錄。我想要做的是在下面的函數中註釋。使用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;
}
,問題是......? – white
如何閱讀一些Hibernate文檔?這是非常基本的東西。順便說一句,如果你對一個客戶感興趣,返回一個列表並沒有多大意義。請參閱http://docs.jboss.org/hibernate/orm/3.6/javadocs/org/hibernate/Session.html#get%28java.lang.Class,%20java.io.Serializable%29和http:// docs。 jboss.org/hibernate/orm/3.6/reference/en-US/html_single/#objectstate-loading –
是的你是對的,我剛剛舉了一個示例演示了我想做什麼, – Hasan