現在、Hibernate + JPA を使用するプロジェクトに取り組んでいます。プロジェクトで何を変更したか正確には覚えていませんが、新しい EntityManagerFactory をインスタンス化しようとするたびに、データベースからすべてのデータが消去されます。
コード スニペットは次のとおりです。
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")」を含む行で、データベース全体がクリアされます。
この問題を解決するためのあらゆるアイデアを使い果たしました...皆さんが助けてくれることを願っています.
前もって感謝します!