mavenjpadependenciesmaven-module

Hibernate and JPA error: duplicate import on dependent Maven project


I have two Maven projects, one called project-data and the other one call project-rest which has a dependency on the project-data project.

The Maven build is successful in the project-data project but it fails in the project-rest project, with the exception:

Caused by: org.hibernate.DuplicateMappingException: duplicate import: TemplatePageTag refers to both com.thalasoft.learnintouch.data.jpa.domain.TemplatePageTag and com.thalasoft.learnintouch.data.dao.domain.TemplatePageTag (try using auto-import="false")

I could see some explanation here: http://isolasoftware.it/2011/10/14/hibernate-and-jpa-error-duplicate-import-try-using-auto-importfalse/

What I don't understand, is why this message does not occur when building the project-data project and occurs when building the project-rest project.

I tried to look up in the pom.xml files to see if there was something in there that could explain the issue.

I also looked up the way the tests are configured and run on the project-rest project.

But I haven't yet seen any thing.


Solution

  • The error is basically due to the fact that the sessionFactory bean underlies two entities with the same logical name TemplatePageTag :

    Since this fall to an unusual case, you will have Hibernate complaining about the case. Mostly because you may run in eventual issues when running some HQL queries (which are basically entity oriented queries) and may have inconsistent results.

    As a solution, you may need either to:


    As I took a look deeper into your project strucure, you may need also to fix entity names for other beans as you have been following the same schema for many other classes, such as com.thalasoft.learnintouch.data.jpa.domain.AdminModule and com.thalasoft.learnintouch.data.dao.domain.AdminModule.