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 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory

Stack Overflow | Markus | 7 months ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Spring-boot & spring-data-jpa Mysql: Error creating bean with name 'entityManagerFactory'

    Stack Overflow | 7 months ago | Markus
    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 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
  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

    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]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    SQL does not work with EchoPet!

    GitHub | 4 years ago | DubstepCraig
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
  6. 0

    how to insert apostrophe data in mysql using jdbc

    Stack Overflow | 3 years ago | puneetjava
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's Trousers' ,'http://www.flipkart.com/voi-jeans-banana-fit-men-s- trousers/p/itmd' at line 1
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. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option (id bigint not null auto_increment, value varchar(255), poll_id bigint, p' at line 1

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0()
  2. Java RT
    Constructor.newInstance
    1. sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)[na:1.8.0_51]
    2. sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)[na:1.8.0_51]
    3. sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)[na:1.8.0_51]
    4. java.lang.reflect.Constructor.newInstance(Constructor.java:422)[na:1.8.0_51]
    4 frames
  3. MySQL jdbc
    StatementImpl.executeUpdate
    1. com.mysql.jdbc.Util.handleNewInstance(Util.java:404)[mysql-connector-java-5.1.39.jar:5.1.39]
    2. com.mysql.jdbc.Util.getInstance(Util.java:387)[mysql-connector-java-5.1.39.jar:5.1.39]
    3. com.mysql.jdbc.SQLError.createSQLException(SQLError.java:942)[mysql-connector-java-5.1.39.jar:5.1.39]
    4. com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)[mysql-connector-java-5.1.39.jar:5.1.39]
    5. com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)[mysql-connector-java-5.1.39.jar:5.1.39]
    6. com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)[mysql-connector-java-5.1.39.jar:5.1.39]
    7. com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)[mysql-connector-java-5.1.39.jar:5.1.39]
    8. com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)[mysql-connector-java-5.1.39.jar:5.1.39]
    9. com.mysql.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1540)[mysql-connector-java-5.1.39.jar:5.1.39]
    10. com.mysql.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2595)[mysql-connector-java-5.1.39.jar:5.1.39]
    11. com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1468)[mysql-connector-java-5.1.39.jar:5.1.39]
    11 frames
  4. org.hibernate.tool
    SchemaMigratorImpl.doMigration
    1. org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:56)[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    2. org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlString(SchemaMigratorImpl.java:431)[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    3. org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlStrings(SchemaMigratorImpl.java:420)[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    4. org.hibernate.tool.schema.internal.SchemaMigratorImpl.createTable(SchemaMigratorImpl.java:236)[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    5. org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:167)[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    6. org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60)[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    6 frames
  5. Hibernate
    SessionFactoryImpl.<init>
    1. org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:134)[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    2. org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101)[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    3. org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:470)[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    3 frames
  6. org.hibernate.boot
    SessionFactoryBuilderImpl.build
    1. org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    1 frame
  7. org.hibernate.jpa
    EntityManagerFactoryBuilderImpl.build
    1. org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)[hibernate-entitymanager-5.0.9.Final.jar:5.0.9.Final]
    1 frame
  8. Spring ORM
    AbstractEntityManagerFactoryBean.afterPropertiesSet
    1. org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)[spring-orm-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    2. org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:338)[spring-orm-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    3. org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373)[spring-orm-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    4. org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362)[spring-orm-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    4 frames
  9. Spring Beans
    AbstractBeanFactory.getBean
    1. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    2. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    3. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    4. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    5. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    6. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    7. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    8. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    8 frames
  10. Spring Context
    AbstractApplicationContext.refresh
    1. org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076)[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    2. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851)[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    3. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    3 frames
  11. Spring Boot
    SpringApplication.run
    1. org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    2. org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    3. org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369)[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    4. org.springframework.boot.SpringApplication.run(SpringApplication.java:313)[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    5. org.springframework.boot.SpringApplication.run(SpringApplication.java:1185)[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    6. org.springframework.boot.SpringApplication.run(SpringApplication.java:1174)[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    6 frames
  12. com.alledu
    AllEduApplication.main
    1. com.alledu.AllEduApplication.main(AllEduApplication.java:10)[bin/:na]
    1 frame
  13. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[na:1.8.0_51]
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[na:1.8.0_51]
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[na:1.8.0_51]
    4. java.lang.reflect.Method.invoke(Method.java:497)[na:1.8.0_51]
    4 frames
  14. org.springframework.boot
    RestartLauncher.run
    1. org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)[spring-boot-devtools-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    1 frame