我目前正在使用Hibernate + JPA的项目。 我不记得我在项目中改变了什么,但每次我尝试实例化一个新的EntityManagerFactory时,它都清除了数据库中的所有数据。Persistence.createEntityManagerFactory清除整个数据库
这里是代码片段:
public abstract class GenericDAO<T> {
protected Class<T> t;
protected EntityManagerFactory managerFactory;
protected EntityManager manager;
protected Session hibernateSession;
public GenericDAO(Class<T> t) {
this.t = t;
this.managerFactory = Persistence.createEntityManagerFactory("hibernatePersistence");
this.manager = this.managerFactory.createEntityManager();
this.hibernateSession = HibernateUtil.getSessionFactory().openSession();
}
在包含 “Persistence.createEntityManagerFactory(” hibernatePersistence “)” 行,整个数据库被清除出去。
我竭尽全力解决这个问题......我希望你们能帮忙。
在此先感谢!
'更新',或'验证'是好的。只要避免'drop-create'。 (+1) – Bozho 2011-04-06 21:31:01
不,我试过这两个建议,没有任何帮助,任何其他的想法? – 2011-04-07 01:25:18
也许你正在使用内存数据库? H2/HSQLDB?什么是您的JDBC URL? – 2011-04-07 06:08:06