Home Error when having primary and secondary table in hibernate
Reply: 0

Error when having primary and secondary table in hibernate

user2222
1#
user2222 Published in July 23, 2018, 9:48 am

I am working on a migration of an EJB application to spring boot. I am using spring boot 1.5.9.RELEASE and use spring data jpa.

The following is one entity sample where I need to map two tables from different schema,

@Entity
@Table(schema = "MY_DB1", name = "APPLICATION")
@SecondaryTable(schema = "MY_DB2", name = "APPLICATION", pkJoinColumns = { @PrimaryKeyJoinColumn(name = "APPLICATION_ID") })
public class Application implements java.io.Serializable {

    private static final long serialVersionUID = -8358325764349116295L;
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "APPLICATIONID", unique = true, nullable = false)
    @NotNull
    private Long id;

I am getting the following error. Its seems the schema name is not considered during the compilation.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource 
[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is 
org.hibernate.boot.spi.InFlightMetadataCollector$DuplicateSecondaryTableException: 
Table with that name [APPLICATION] already associated with entity

But this entity works fine with the EJB application. In that, they have used hibernate version

       <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.2.4.sp1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.2.1.ga</version>
            <scope>provided</scope>
        </dependency>

The issue is that I am not able to change the table names as this is an application which had been used for a long time.

I did some research regarding this but didn't found any good solution.

Thanks.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.355241 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO