We're updating the issue view to help you get more done. 

'Duplicate table mapping' error after upgrade from Hibernate 4.2 to Hibernate 5

Description

We have a JPA entity model which consists of two different entities which are mapped to the same database table. The reason why two separate entities exists is that we use them in two separate parts of the application (separate application modules) and they differ in attributes which they hold. This scenario was working perfectly in Hibernate 4.2.18.

After upgrade to 5.2.10 (JPA 2.1), we started experiencing the DuplicateMappingException: Duplicate table mapping, which occurs on the application startup. The entities are defined as follows:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 package abc; @Entity(name = "ComponentFolder") @Table(name = "component_folder") public class Folder extends AbstractContentEntity { @Column(name = "name") private String name; @OneToMany(fetch = FetchType.LAZY, mappedBy = "parent") private Set<AbstractContentEntity> content; } package xyz; @Entity @Table(name = "component_folder") @SequenceGenerator(name = Folder.SQ_CONTENT_ID, sequenceName = Folder.SQ_CONTENT_ID) public class Folder extends AbstractVersionedEntity implements Serializable { static final String SQ_CONTENT_ID = "sq_content_id"; @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = SQ_CONTENT_ID) private Long id; @Column(name = "name", nullable = false) private String name; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "folder_id") private Folder parent; } package abc; @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @SequenceGenerator(name = AbstractContentEntity.GENERATOR_NAME, sequenceName = AbstractContentEntity.GENERATOR_NAME) public abstract class AbstractContentEntity extends AbstractVersionedEntity { static final String GENERATOR_NAME = "sq_content_id"; @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = GENERATOR_NAME) private Long id; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "folder_id") private Folder parent; } package base; @MappedSuperclass public abstract class AbstractVersionedEntity extends AbstractEntity { @Version @Column(name = "internal_version") private Integer internalVersion; } package base; @MappedSuperclass public abstract class AbstractEntity extends AbstractEntityBase { @Column(nullable = false, length = 40, name = "guid", unique = true) private String guid; } package base; @MappedSuperclass public abstract class AbstractEntityBase implements Serializable { }

The exception we receive is:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 [9/14/17 10:20:46:669 CEST] 0000008a webapp E com.ibm.ws.webcontainer.webapp.WebApp notifyServletContextCreated SRVE0283E: Exception caught while initializing context: {0} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repositoryPersistenceUnit': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate table mapping component_folder at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1702) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$34.0000000096B007C0.getObject(Unknown Source) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:858) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:409) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103) at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1826) at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:442) at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:88) at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:171) at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:904) at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:789) at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:427) at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:719) at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1247) at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1514) at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:704) at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:1096) at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:799) at com.ibm.ws.runtime.component.ApplicationMgrImpl$5.run(ApplicationMgrImpl.java:2315) at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5488) at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5614) at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255) at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2320) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:436) at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:379) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access$500(CompositionUnitMgrImpl.java:127) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$CUInitializer.run(CompositionUnitMgrImpl.java:985) at com.ibm.wsspi.runtime.component.WsComponentImpl$_AsynchInitializer.run(WsComponentImpl.java:524) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1909) Caused by: org.hibernate.DuplicateMappingException: Duplicate table mapping component_folder at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.addDenormalizedTable(InFlightMetadataCollectorImpl.java:750) at org.hibernate.cfg.annotations.TableBinder.buildAndFillTable(TableBinder.java:499) at org.hibernate.cfg.annotations.EntityBinder.bindTable(EntityBinder.java:670) at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:602) at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:249) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:222) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:265) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:858) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:885) at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:358) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:384) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:373) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1761) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1698) ... 38 more

Although we run this application on WebSphere, we do not use the default (built-in) Java Persistence provider.

Thanks in advance for any insight and suggestions.

Environment

WebSphere AS 9.0 (Classic Edition) + Oracle 12c

Status

Assignee

Unassigned

Reporter

Stanislav Novák

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

4.2.19

Components

Affects versions

5.2.10

Priority

Major