Session session = factory.openSession();
Transaction tx = null;
List<Fund> funds = new ArrayList();
try {
tx = session.beginTransaction();
String hql = "FROM Fund";// name of class, not a column
Query query = session.createQuery(hql);
funds = query.getResultList();
tx.commit();
} catch (HibernateException e) {
if (tx != null) tx.rollback();
e.printStackTrace();
} finally {
session.close();
return funds;
}
}
我在已经填充的MySql数据库上调用以上代码。它会擦除所有数据并返回空的资金清单。程序终止后,数据库为空。没有错误,在执行过程中不会发生异常。怎么了?
最佳答案
是线
创建
在导致数据库被删除的hibernate-lending.cfg.xml中。