"SchemaManagementException: SQL strings added more than once" in Hibernate

Solution Verified - Updated -

Issue

  • Two different entities in a single persistence unit are mapped to tables by the same name which reside in different database schemas
  • The tables each have unique constraints on identically named, non-primary key properties

    @Entity
    @Table(name = "employee", schema = "testone")
    public class EmployeeOne {
            @Id
            private String name;
    
            @Column(unique = true)
            private String title;
            ...
    }
    
    @Entity
    @Table(name = "employee", schema = "testtwo")
    public class EmployeeTwo {
            @Id
            private String name;
    
            @Column(unique = true)
            private String title;
            ...
    }
    
  • When Hibernate is used to generate the database artifacts, (e.g. hibernate.hbm2ddl.auto=create-drop), an exception is raised

    ... org.hibernate.tool.schema.spi.SchemaManagementException: SQL strings added more than once for: employee.UK-UK_....
        at org.hibernate.tool.schema.internal.SchemaCreatorImpl.checkExportIdentifier(SchemaCreatorImpl.java:408)
        at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:347)
        at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:165)
        at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:134)
        at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:120)
        at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:148)
        at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:65)
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:478)
        at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:423)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:880)
        ...
    

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 7
  • Hibernate 5

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content