java – Duplicate mapping error: org.hibernate.DuplicateMappingExceptionn

Question:

I'm using Hibernate 5 and I'm having the following problem:

Caused by: org.hibernate.DuplicateMappingException: duplicate import: br.edu.unifeob.entidades.apuracao.Avaliacao refers to both br.edu.unifeob.entidades.apuracao.Avaliacao and br.edu.unifeob.entidades.apuracao.Serie (try using auto-import="false")
at org.hibernate.cfg.Configuration$MappingsImpl.addImport(Configuration.java:2892)
at org.hibernate.cfg.annotations.EntityBinder.bindEntity(EntityBinder.java:401)

I've already tried to annotate my entities that way but it didn't work:

@Entity(name="br.edu.unifeob.entidades.apuracao.Avaliacao")
@Table(name="Avaliacao")
public class Avaliacao {
...
}

@Entity(name="br.edu.unifeob.entidades.base.Avaliacao")
@Table(name="Avaliacao")
public class Avaliacao{
...
}

The two classes are in different persistence units. Does anyone know what can it be? I've already researched it and the only way I found to solve the problem is to use the name of the @Entity annotation to differentiate the entities.

Answer:

Will one of these entities be used for reading only?
If so, you can include @Immutable in this entity:

@Entity
@Table(name="Avaliacao")
public class Avaliacao {
...
}

@Entity
@Table(name="Avaliacao")
@Immutable
public class Avaliacao {
...
}

As an example here: https://stackoverflow.com/questions/29007676/how-to-map-two-hibernate-entities-on-the-same-database-table

Scroll to Top