hibernate的HibernateSessionFactory
小弟初学hibernate,有些问题不是很明了!
想请教下。
就是用myelipse完成hibernate设置后,会自动产生这个文件。
那这个文件需要更改么?直接在让与数据库交互的JAVA类把它实例化就可以了?
另外有段代码我不是很明白:
public void findAllCustomers(ServletContext context,OutputStream out) throws Exception{
// Ask for a session using the JDBC information we've configured
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
List customers=session.find("from Customer as c order by c.name asc");
for (Iterator it = customers.iterator(); it.hasNext();) {
printCustomer(context,out,(Customer) it.next());
}
// We're done; make our changes permanent
tx.commit();
}catch (Exception e) {
if (tx != null) {
// Something went wrong; discard all partial changes
tx.rollback();
}
throw e;
} finally {
// No matter what, close the session
session.close();
}
}
中间的 tx = session.beginTransaction();是只开启数据库事物么?可以这样理解么?