java.sql.SQLException: Can't create table 'supportcenter.#sql-62d_d3' (errno: 121)

Stack Overflow | shantaram_t | 3 months ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    I have a Mysql duplicate column name exception after moving to Hibernate 5 from 4 when HBM2DDL_AUTO is set to "update". It seems to cause exceptions with various combination of mixed case column name (with @Column for example) and on linux (case sensitive) but not on Windows. I have this made up code to test one particular case. {code:java} import java.sql.SQLException; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.cfg.Environment; import org.hibernate.tool.hbm2ddl.SchemaUpdate; import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; @Entity class My { @Id public int getId() { return 0; } @Column(name="Ul") public int getValue() { return 0; } public void setId(final int _id) { } public void setValue(int value) { } } public class Test { public static void main(String[] args) throws SQLException { MysqlDataSource ds = new MysqlDataSource(); ds.setUrl("jdbc:mysql://192.168.1.6/test2?user=root"); new SchemaUpdate((MetadataImplementor) new MetadataSources(new StandardServiceRegistryBuilder() .applySetting(Environment.DATASOURCE, ds).build()) .addAnnotatedClass( My.class ) .buildMetadata()).execute(true, true); } } {code} Output on run with no existing table {noformat} create table My (id integer not null, Ul integer, primary key (id)) {noformat} Output on run with existing table {code:java} alter table My add column Ul integer Exception in thread "main" org.hibernate.tool.schema.spi.SchemaManagementException: Unable to execute schema management to JDBC target [alter table My add column Ul integer] at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:58) at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlString(SchemaMigratorImpl.java:332) at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlStrings(SchemaMigratorImpl.java:350) at org.hibernate.tool.schema.internal.SchemaMigratorImpl.migrateTable(SchemaMigratorImpl.java:159) at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:101) at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:59) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:129) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:97) at Test.main(Test.java:41) Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Duplicate column name 'Ul' at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at com.mysql.jdbc.Util.handleNewInstance(Util.java:389) at com.mysql.jdbc.Util.getInstance(Util.java:372) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:980) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3835) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3771) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2531) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1618) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1549) at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:55) ... 8 more {code}

    Hibernate JIRA | 2 years ago | Trong Dinh
    org.hibernate.tool.schema.spi.SchemaManagementException: Unable to execute schema management to JDBC target [alter table My add column Ul integer]
  2. 0

    I have a Mysql duplicate column name exception after moving to Hibernate 5 from 4 when HBM2DDL_AUTO is set to "update". It seems to cause exceptions with various combination of mixed case column name (with @Column for example) and on linux (case sensitive) but not on Windows. I have this made up code to test one particular case. {code:java} import java.sql.SQLException; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.cfg.Environment; import org.hibernate.tool.hbm2ddl.SchemaUpdate; import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; @Entity class My { @Id public int getId() { return 0; } @Column(name="Ul") public int getValue() { return 0; } public void setId(final int _id) { } public void setValue(int value) { } } public class Test { public static void main(String[] args) throws SQLException { MysqlDataSource ds = new MysqlDataSource(); ds.setUrl("jdbc:mysql://192.168.1.6/test2?user=root"); new SchemaUpdate((MetadataImplementor) new MetadataSources(new StandardServiceRegistryBuilder() .applySetting(Environment.DATASOURCE, ds).build()) .addAnnotatedClass( My.class ) .buildMetadata()).execute(true, true); } } {code} Output on run with no existing table {noformat} create table My (id integer not null, Ul integer, primary key (id)) {noformat} Output on run with existing table {code:java} alter table My add column Ul integer Exception in thread "main" org.hibernate.tool.schema.spi.SchemaManagementException: Unable to execute schema management to JDBC target [alter table My add column Ul integer] at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:58) at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlString(SchemaMigratorImpl.java:332) at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlStrings(SchemaMigratorImpl.java:350) at org.hibernate.tool.schema.internal.SchemaMigratorImpl.migrateTable(SchemaMigratorImpl.java:159) at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:101) at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:59) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:129) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:97) at Test.main(Test.java:41) Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Duplicate column name 'Ul' at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at com.mysql.jdbc.Util.handleNewInstance(Util.java:389) at com.mysql.jdbc.Util.getInstance(Util.java:372) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:980) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3835) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3771) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2531) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1618) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1549) at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:55) ... 8 more {code}

    Hibernate JIRA | 2 years ago | Trong Dinh
    org.hibernate.tool.schema.spi.SchemaManagementException: Unable to execute schema management to JDBC target [alter table My add column Ul integer]
  3. 0

    Conflito de dependĂȘncias com Wildfly 10

    Google Groups | 1 year ago | Marcelo Eugenio
    javax.persistence.PersistenceException: [PersistenceUnit: sigerhHidrometeorologiaSemar] Unable to build Hibernate SessionFactory
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Why can't hibernate execute command

    Stack Overflow | 1 year ago | lord-ivan
    org.hibernate.tool.schema.spi.CommandAcceptanceException: Unable to execute command [alter table UserRoleStatus add constraint FKon0rvnj31qoi3177vwn868stx foreign key (roleId) references USERROLES (roleId)]
  6. 0

    Schema Exception Hibernate One to Many

    Stack Overflow | 9 months ago | Hadrian Blackwater
    org.hibernate.tool.schema.spi.CommandAcceptanceException: Unable to execute command [ alter table OrderItem add constraint FK1d77ns82kvwa2hwab9k7xcaog foreign key (order_id) references Order (order_id)]
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.sql.SQLException

    Can't create table 'supportcenter.#sql-62d_d3' (errno: 121)

    at com.mysql.jdbc.SQLError.createSQLException()
  2. MySQL jdbc
    StatementImpl.executeUpdate
    1. com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    2. com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
    3. com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
    4. com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
    5. com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
    6. com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618)
    7. com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1749)
    8. com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1666)
    8 frames
  3. org.hibernate.tool
    SchemaMigratorImpl.doMigration
    1. org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:56)
    2. org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlString(SchemaMigratorImpl.java:371)
    3. org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlStrings(SchemaMigratorImpl.java:360)
    4. org.hibernate.tool.schema.internal.SchemaMigratorImpl.applyForeignKeys(SchemaMigratorImpl.java:325)
    5. org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:157)
    6. org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:59)
    6 frames
  4. Hibernate
    SessionFactoryImpl.<init>
    1. org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:129)
    2. org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:97)
    3. org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:481)
    3 frames
  5. org.hibernate.boot
    SessionFactoryBuilderImpl.build
    1. org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
    1 frame
  6. Hibernate
    Configuration.buildSessionFactory
    1. org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
    2. org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
    2 frames
  7. Spring ORM
    LocalSessionFactoryBean.afterPropertiesSet
    1. org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372)
    2. org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:454)
    3. org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:439)
    3 frames
  8. Spring Beans
    DefaultListableBeanFactory.preInstantiateSingletons
    1. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
    2. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
    3. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    4. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    5. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    6. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    7. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    8. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    9. org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
    10. org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
    11. org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
    12. org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
    13. org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    14. org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    15. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
    16. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    17. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    18. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    19. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    20. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    21. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    22. org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
    23. org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
    24. org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
    25. org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
    26. org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    27. org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    28. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
    29. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    30. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    31. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    32. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    33. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    34. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    35. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    35 frames
  9. Spring Context
    AbstractApplicationContext.refresh
    1. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    2. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    2 frames
  10. Spring MVC
    HttpServletBean.init
    1. org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663)
    2. org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629)
    3. org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677)
    4. org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548)
    5. org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489)
    6. org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    6 frames
  11. JavaServlet
    GenericServlet.init
    1. javax.servlet.GenericServlet.init(GenericServlet.java:160)
    1 frame
  12. Glassfish Core
    ContainerBase$StartChild.call
    1. org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
    2. org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
    3. org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    4. org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
    5. org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
    6. org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    7. org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    8. org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    8 frames
  13. Java RT
    Thread.run
    1. java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    2. java.util.concurrent.FutureTask.run(FutureTask.java:166)
    3. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    4. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    5. java.lang.Thread.run(Thread.java:722)
    5 frames