Fix for Hibernate error “Use of the same entity name twice”

前端 未结 6 965
灰色年华
灰色年华 2020-12-17 17:29

How you fix the following Hibernate error:

What does \"Use of the same entity name twice\".

6条回答
  •  被撕碎了的回忆
    2020-12-17 18:00

    I've come across this error a few different times. The causes were as follows:

    1. I had a duplicate mapping in my hibernate configuration (check config file/code)
    2. Two threads were attempting to build the HibernateSessionFactory object at the same time. A synchronized lock on the initialization code fixed this.
    3. An attempt to build the HibernateSessionFactory failed, but is being called again. The Hibernate Configuration object didn't get cleared out, so the entities are being processed again.
    4. You have two entity classes being mapped to the same file. Hibernate will choke on this as well.

提交回复
热议问题