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

Error when having primary and secondary table in hibernate

user2222 Published in March 23, 2018, 7:02 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,

@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)
    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 
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



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.


You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO