We are trying to migrate our application from hibernate 3 to hibernate 5 (From 3.6.10.Final to 5.1.10.Final to be specific).
I was able to resolve many compilation issues.
But application start fails with the following error.
Invocation of init method failed; nested exception is org.hibernate.boot.spi.InFlightMetadataCollector$DuplicateSecondaryTableException: Table with that name [Cluster] already associated with entity
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:592)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:370)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:754)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
NOTE:
I have 2 schema schema1 & schema2 Cluster entity needs to encapsulate both. Some columns from schema1 and some columns from schema2.
There are no changes in table structure. just hibernate upgrade.
@org.hibernate.annotations.Entity(optimisticLock = OptimisticLockType.DIRTY, dynamicUpdate = true)
is replaced with
@Entity
@OptimisticLocking(type = OptimisticLockType.DIRTY)
@DynamicUpdate
The below is the entity with used annotations.
Used in hibernate 3
@GenerateMutator
@Table(name = “cluster”, schema = “schema1”)
@SecondaryTable(name = “Cluster”, schema = “schema2”, pkJoinColumns = { @PrimaryKeyJoinColumn(name = “id”) })
@org.hibernate.annotations.Table(appliesTo = “Cluster”, optional = false)
@Entity
@org.hibernate.annotations.Entity(optimisticLock = OptimisticLockType.DIRTY, dynamicUpdate = true)
public class Cluster
Modified in hibernate 5
@GenerateMutator
@Table(name = “cluster”, schema = “C”)
@SecondaryTable(name = “cluster”, schema = “schema2”, pkJoinColumns = { @PrimaryKeyJoinColumn(name = “id”) })
@org.hibernate.annotations.Table(appliesTo = “Cluster”, optional = false)
@Entity
@OptimisticLocking(type = OptimisticLockType.DIRTY)
@DynamicUpdate
public class Cluster
Can some one guide me on what could be the issue and any solution for this ?