-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Hibernate SchemaUpdate trying to rewrite all foreign keys
PostPosted: Tue Apr 05, 2016 9:58 pm 
Newbie

Joined: Sat Feb 27, 2016 1:47 am
Posts: 16
So this issue just started occurring today, and I've not had issue with it before. I don't think I've changed anything that would cause this (though it's possible), I haven't changed any configuration settings for hibernate.

Basically when I start up tomcat, and the hbm2dll SchemaUpdate process runs, it throws a whole lot of exceptions like:

Code:
org.hibernate.tool.schema.spi.CommandAcceptanceException: Unable to execute command [alter table database.user_account add constraint FKplcj46p492hdawgppqi9mlv05 foreign key (country_id) references database.countries (country_id)]

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Can't write; duplicate key in table '#sql-15b8_6de'


If I drop all the foreign keys from my database, the SchemaUpdate runs fine and it recreates all the foreign keys correctly. However when it runs a subsequent time, it will try to write the foreign keys again, and throw errors.

I initially was using Hibernate version 5.0.6.Final. This would cause the process to fail after the first exception. Upon updating to 5.1.0.Final, the exceptions are caught and the process continues - it attempts to create >100 foreign keys, each of them throws the same duplicate key exception, but at least it doesn't halt execution.

So is anyone familiar with this issue? Or know why the SchemaUpdate process is suddenly failing to recognise existing foreign keys in my MySQL database?

Full stack trace:

Code:
2016-04-06 13:42:02,218 WARN  [ContainerBackgroundProcessor[StandardEngine[Catalina]]] internal.ExceptionHandlerLoggedImpl (ExceptionHandlerLoggedImpl.java:27) - GenerationTarget encountered exception accepting command : Unable to execute command [alter table database.user_rules add constraint FKgkxv5wfmwdpn2kt82b4ix86b6 foreign key (user_id) references database.user_account (id)]
org.hibernate.tool.schema.spi.CommandAcceptanceException: Unable to execute command [alter table database.user_rules add constraint FKgkxv5wfmwdpn2kt82b4ix86b6 foreign key (user_id) references database.user_account (id)]
        at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:63) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
        at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlString(SchemaMigratorImpl.java:567) [hibernate-core-5.1.0.Final.jar:5.1.0.Final]
        at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlStrings(SchemaMigratorImpl.java:551) [hibernate-core-5.1.0.Final.jar:5.1.0.Final]
        at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applyForeignKeys(SchemaMigratorImpl.java:510) [hibernate-core-5.1.0.Final.jar:5.1.0.Final]
        at org.hibernate.tool.schema.internal.SchemaMigratorImpl.performMigration(SchemaMigratorImpl.java:309) [hibernate-core-5.1.0.Final.jar:5.1.0.Final]
        at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:137) [hibernate-core-5.1.0.Final.jar:5.1.0.Final]
        at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:110) [hibernate-core-5.1.0.Final.jar:5.1.0.Final]
        at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:176) [hibernate-core-5.1.0.Final.jar:5.1.0.Final]
        at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:64) [hibernate-core-5.1.0.Final.jar:5.1.0.Final]
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:458) [hibernate-core-5.1.0.Final.jar:5.1.0.Final]
        at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:465) [hibernate-core-5.1.0.Final.jar:5.1.0.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:881) [hibernate-entitymanager-5.1.0.Final.jar:5.1.0.Final]
        at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) [spring-orm-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) [spring-orm-.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:319) [spring-orm-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054) [spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:829) [spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) [spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444) [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326) [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4729) [catalina.jar:8.0.26]
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167) [catalina.jar:8.0.26]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.26]
        at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3746) [catalina.jar:8.0.26]
        at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:292) [catalina.jar:8.0.26]
        at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5528) [catalina.jar:8.0.26]
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1377) [catalina.jar:8.0.26]
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381) [catalina.jar:8.0.26]
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381) [catalina.jar:8.0.26]
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1349) [catalina.jar:8.0.26]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Can't write; duplicate key in table '#sql-15b8_6de'
        at sun.reflect.GeneratedConstructorAccessor378.newInstance(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_45]
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.38.jar:5.1.38]
        at com.mysql.jdbc.Util.getInstance(Util.java:387) ~[mysql-connector-java-5.1.38.jar:5.1.38]
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:932) ~[mysql-connector-java-5.1.38.jar:5.1.38]
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878) ~[mysql-connector-java-5.1.38.jar:5.1.38]
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) ~[mysql-connector-java-5.1.38.jar:5.1.38]
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478) ~[mysql-connector-java-5.1.38.jar:5.1.38]
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625) ~[mysql-connector-java-5.1.38.jar:5.1.38]
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2547) ~[mysql-connector-java-5.1.38.jar:5.1.38]
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2505) ~[mysql-connector-java-5.1.38.jar:5.1.38]
        at com.mysql.jdbc.StatementImpl.executeInternal(StatementImpl.java:840) ~[mysql-connector-java-5.1.38.jar:5.1.38]
        at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:740) ~[mysql-connector-java-5.1.38.jar:5.1.38]
        at com.zaxxer.hikari.proxy.StatementProxy.execute(StatementProxy.java:83) ~[HikariCP-java6-2.3.12.jar:?]
        at com.zaxxer.hikari.proxy.HikariStatementProxy.execute(HikariStatementProxy.java) ~[HikariCP-java6-2.3.12.jar:?]
        at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:51) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
        ... 39 more


Top
 Profile  
 
 Post subject: Re: Hibernate SchemaUpdate trying to rewrite all foreign keys
PostPosted: Wed Apr 06, 2016 3:05 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Is it hbmddl=update you are running?


Top
 Profile  
 
 Post subject: Re: Hibernate SchemaUpdate trying to rewrite all foreign keys
PostPosted: Wed Apr 06, 2016 7:01 pm 
Newbie

Joined: Sat Feb 27, 2016 1:47 am
Posts: 16
mihalcea_vlad wrote:
Is it hbmddl=update you are running?

yes that's correct


Top
 Profile  
 
 Post subject: Re: Hibernate SchemaUpdate trying to rewrite all foreign keys
PostPosted: Wed Apr 06, 2016 7:38 pm 
Newbie

Joined: Sat Feb 27, 2016 1:47 am
Posts: 16
I am no longer having this issue. I haven't changed anything in my project, so perhaps some kind of caching issue?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.