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

前端 未结 6 900
灰色年华
灰色年华 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:14

    I have this error (duplicate import) recently: two entities with the same name 'MyEntity' but from different packages/modules: com.test1.MyEntity com.test2.MyEntity

    I didn't use them but they were loaded by hibernate to jboss. I wasn't allowed to change entities so I had to do some workaround.

    1. Add to persistance.xml. It prevented of throwing duplicate exception while deploying to jboss. But exception was thrown when my query was called.
    2. Use JPQL query. In my case it was looked like: entityManager.createQuery("Select a.Name, b.name from AEntity a, BEntity b where a.ID = b.parentID")

    It's ugly but it's a workaround.

提交回复
热议问题