Paulo Victor
Paulo Victor

Reputation: 926

Persistence.createEntityManagerFactory clearing out the whole database

I'm currently working with a project using Hibernate + JPA. I don't recall exactly what I changed in the project, but everytime I try to instantiate a new EntityManagerFactory, it clears out all of the data from the database.

Here is the code snippet:

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();
}

In the line that contains "Persistence.createEntityManagerFactory("hibernatePersistence")", the whole database is cleared out.

I exhausted every idea for solving this issue... I hope you guys can help.

Thanks in advance!

Upvotes: 0

Views: 1493

Answers (2)

Paulo Victor
Paulo Victor

Reputation: 926

Resolved by deleting and creating a fresh new persistence.xml. Don't know why this problme occured, but nevermind, it works now...

Upvotes: 0

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340863

Look for hibernate.hbm2ddl.auto property somewhere in your project (probably persistence.xml file) and remove it or change its value to validate. See also:

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html#configuration-optional

Upvotes: 2

Related Questions