为了账号安全,请及时绑定邮箱和手机立即绑定

在配置异常处理后 ddl-auto: update报错

在跟着老师到 统一异常处理 下 这里的时候  数据库就不能自动创建了        ddl-auto:  修改成create和 Validate 就没有问题  这是为什么。报错如下

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

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) ~[spring-context-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856) ~[spring-context-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.6.BUILD-SNAPSHOT.jar:1.4.6.BUILD-SNAPSHOT]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-1.4.6.BUILD-SNAPSHOT.jar:1.4.6.BUILD-SNAPSHOT]

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372) [spring-boot-1.4.6.BUILD-SNAPSHOT.jar:1.4.6.BUILD-SNAPSHOT]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-1.4.6.BUILD-SNAPSHOT.jar:1.4.6.BUILD-SNAPSHOT]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187) [spring-boot-1.4.6.BUILD-SNAPSHOT.jar:1.4.6.BUILD-SNAPSHOT]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176) [spring-boot-1.4.6.BUILD-SNAPSHOT.jar:1.4.6.BUILD-SNAPSHOT]

at com.example.Girls2Application.main(Girls2Application.java:10) [classes/:na]

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory

at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]

at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370) ~[spring-orm-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359) ~[spring-orm-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.8.BUILD-SNAPSHOT.jar:4.3.8.BUILD-SNAPSHOT]

... 16 common frames omitted

Caused by: org.hibernate.exception.GenericJDBCException: Unable to obtain JDBC Connection

at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.tool.schema.extract.internal.ExtractionContextImpl.getJdbcConnection(ExtractionContextImpl.java:65) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.tool.schema.extract.internal.ExtractionContextImpl.getJdbcDatabaseMetaData(ExtractionContextImpl.java:75) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.locateTableInNamespace(InformationExtractorJdbcDatabaseMetaDataImpl.java:339) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.getTable(InformationExtractorJdbcDatabaseMetaDataImpl.java:241) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.getTableInformation(DatabaseInformationImpl.java:105) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:162) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:134) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:472) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]

... 22 common frames omitted

 


正在回答

7 回答

这个问题困扰了我好几天,终于搞定了,记录一下,只要在配置文件中增加数据库方言即可:

#指定数据库方言
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.SQLServerDialect

注意:我这里用的是SQLServer数据库,如果你用的是MySql数据库的话,可以换成下面的:

#

#指定数据库方言
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MYSQL5Dialect


1 回复 有任何疑惑可以回复我~

我也一样啊,来个大神求教

0 回复 有任何疑惑可以回复我~

我也有类似的问题

0 回复 有任何疑惑可以回复我~

我也是相同问题!

0 回复 有任何疑惑可以回复我~

问题解决了没?我也出现这个问题了

0 回复 有任何疑惑可以回复我~

可能是数据库的问题,新建数据库,重新建表试试,我就是这样做的

0 回复 有任何疑惑可以回复我~

jar包有冲突吧。

0 回复 有任何疑惑可以回复我~
#1

teresazoom

怎么看是哪里冲突了?
2017-05-02 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

在配置异常处理后 ddl-auto: update报错

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信