Java JPA/Hibernate generates database schema twice

Viewed 531

I recently tried switching my application from Hibernate's SessionFactory to JPA's EntityManager for a Spring MVC project.

When I run my application with Jetty, the database schema is created twice. (I have the hbm2ddl.auto set to 'create').

More specifically, I see this output twice:

INFO: Building JPA EntityManagerFactory for persistence unit 'default'
INFO: Initialized JPA EntityManagerFactory for persistence unit 'default'

The generated sql by hibernate also shows the exact same SQL statements repeated twice.

Somehow the entitymanagerfactory is being created twice.

I am using Hibernate version 5.2.9.Final, Spring version 4.3.5.RELEASE

Unfortunately the project does not belong to me, so I do not think I can release code samples. But I am wondering if anyone else has encountered this issue, and I would really appreciate it if anyone could point me in a general direction of where the problem might be.

I have tried switching between LocalEntityManagerFactoryBean and LocalContainerEntityManagerFactoryBean

I have also switched between using dataSource and persistence.xml

I have also tried filtering <context:component-scan> in dispatcher-servlet.xml to exclude scanning for @Component (to avoid potentially having some beans scanned twice), but none of these have worked!

Any help would be appreciated.

0 Answers
Related