在 Spring Boot 2、Hibernate、PostgreSQL 中通过 JDBC 语句执行 DDL 时出错

Posted

技术标签:

【中文标题】在 Spring Boot 2、Hibernate、PostgreSQL 中通过 JDBC 语句执行 DDL 时出错【英文标题】:Error Executing DDL via JDBC statement in Spring Boot 2, Hibernate, PostgreSQL 【发布时间】:2019-03-30 22:44:54 【问题描述】:

我想通过我的 Spring boot 2.0.6 应用程序使用 PostgreSQL 连接到 Heroku 云,但我遇到了一个异常。它似乎在 Spring boot 1 中运行良好,所以它可能是 Spring boot 2 的问题。我尝试以不同的方式修改我的 applicaton.properties,但都没有成功。

我的日志:

2018-10-26 09:56:14.762  INFO 7536 --- [  restartedMain] com.greenenergy.GreenEnergyApplication   : Starting GreenEnergyApplication on localhost.localdomain with PID 7536 (/home/alexanderp/Projects/greenenergy/greenenergy/target/classes started by alexanderp in /home/alexanderp/Projects/greenenergy/greenenergy)
2018-10-26 09:56:14.764  INFO 7536 --- [  restartedMain] com.greenenergy.GreenEnergyApplication   : No active profile set, falling back to default profiles: default
2018-10-26 09:56:14.821  INFO 7536 --- [  restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6c532aae: startup date [Fri Oct 26 09:56:14 CEST 2018]; root of context hierarchy
2018-10-26 09:56:15.861  INFO 7536 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$5e1ea8db] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-10-26 09:56:16.254  INFO 7536 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-10-26 09:56:16.273  INFO 7536 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-10-26 09:56:16.273  INFO 7536 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.34
2018-10-26 09:56:16.277  INFO 7536 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : Loaded APR based Apache Tomcat Native library [1.2.16] using APR version [1.6.3].
2018-10-26 09:56:16.278  INFO 7536 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2018-10-26 09:56:16.278  INFO 7536 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2018-10-26 09:56:16.280  INFO 7536 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : OpenSSL successfully initialized [OpenSSL 1.1.0h-fips  27 Mar 2018]
2018-10-26 09:56:16.332  INFO 7536 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-10-26 09:56:16.332  INFO 7536 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1513 ms
2018-10-26 09:56:16.392  INFO 7536 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-10-26 09:56:16.396  INFO 7536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-10-26 09:56:16.396  INFO 7536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-10-26 09:56:16.396  INFO 7536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-10-26 09:56:16.396  INFO 7536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-10-26 09:56:16.585  INFO 7536 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2018-10-26 09:56:17.412  INFO 7536 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2018-10-26 09:56:17.452  INFO 7536 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-10-26 09:56:17.465  INFO 7536 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2018-10-26 09:56:17.531  INFO 7536 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate Core 5.2.17.Final
2018-10-26 09:56:17.532  INFO 7536 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2018-10-26 09:56:17.564  INFO 7536 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations 5.0.1.Final
2018-10-26 09:56:17.655  INFO 7536 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect
2018-10-26 09:56:17.667  INFO 7536 --- [  restartedMain] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000422: Disabling contextual LOB creation as connection was null
2018-10-26 09:56:17.668  INFO 7536 --- [  restartedMain] org.hibernate.type.BasicTypeRegistry     : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@289d236a
2018-10-26 09:56:18.172  WARN 7536 --- [  restartedMain] o.h.t.s.i.ExceptionHandlerLoggedImpl     : GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375) [hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:359) [hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.applyConstraintDropping(SchemaDropperImpl.java:331) [hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:230) [hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:154) [hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:126) [hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112) [hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:144) [hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72) [hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:312) [hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:462) [hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:892) [hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) [spring-orm-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) [spring-orm-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) [spring-orm-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) [spring-orm-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) [spring-orm-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1753) [spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1690) [spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573) [spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) [spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) [spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) [spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) [spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1087) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at com.greenenergy.GreenEnergyApplication.main(GreenEnergyApplication.java:11) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_171]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_171]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_171]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.0.6.RELEASE.jar:2.0.6.RELEASE]
Caused by: org.postgresql.util.PSQLException: ERROR: relation "story" does not exist
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440) ~[postgresql-42.2.5.jar:42.2.5]
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183) ~[postgresql-42.2.5.jar:42.2.5]
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308) ~[postgresql-42.2.5.jar:42.2.5]
    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441) ~[postgresql-42.2.5.jar:42.2.5]
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365) ~[postgresql-42.2.5.jar:42.2.5]
    at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:307) ~[postgresql-42.2.5.jar:42.2.5]
    at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:293) ~[postgresql-42.2.5.jar:42.2.5]
    at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:270) ~[postgresql-42.2.5.jar:42.2.5]
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:266) ~[postgresql-42.2.5.jar:42.2.5]
    at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-2.7.9.jar:na]
    at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-2.7.9.jar:na]
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    ... 40 common frames omitted

2018-10-26 09:56:18.223  WARN 7536 --- [  restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 0, SQLState: 00000
2018-10-26 09:56:18.223  WARN 7536 --- [  restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper   : table "blogger" does not exist, skipping
2018-10-26 09:56:18.274  WARN 7536 --- [  restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 0, SQLState: 00000
2018-10-26 09:56:18.275  WARN 7536 --- [  restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper   : table "story" does not exist, skipping
2018-10-26 09:56:18.326  WARN 7536 --- [  restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 0, SQLState: 00000
2018-10-26 09:56:18.326  WARN 7536 --- [  restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper   : sequence "hibernate_sequence" does not exist, skipping
2018-10-26 09:56:18.553  INFO 7536 --- [  restartedMain] o.h.t.schema.internal.SchemaCreatorImpl  : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@504b3d51'
2018-10-26 09:56:18.560  INFO 7536 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-10-26 09:56:19.294  INFO 7536 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-26 09:56:19.526  INFO 7536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6c532aae: startup date [Fri Oct 26 09:56:14 CEST 2018]; root of context hierarchy
2018-10-26 09:56:19.552  WARN 7536 --- [  restartedMain] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2018-10-26 09:56:19.576  INFO 7536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "[/error]" onto public java.lang.String com.greenenergy.controller.ErrorPageController.error(org.springframework.ui.Model,javax.servlet.http.HttpServletRequest)
2018-10-26 09:56:19.577  INFO 7536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "[/]" onto public java.lang.String com.greenenergy.controller.HomeController.stories(org.springframework.ui.Model)
2018-10-26 09:56:19.578  INFO 7536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "[/story]" onto public java.lang.String com.greenenergy.controller.HomeController.story(org.springframework.ui.Model)
2018-10-26 09:56:19.578  INFO 7536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "[/title/title]" onto public java.lang.String com.greenenergy.controller.HomeController.searchForUser(java.lang.String,org.springframework.ui.Model) throws java.lang.Exception
2018-10-26 09:56:19.610  INFO 7536 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-26 09:56:19.610  INFO 7536 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-10-26 09:56:19.624  INFO 7536 --- [  restartedMain] .m.m.a.ExceptionHandlerExceptionResolver : Detected @ExceptionHandler methods in exceptionGeneral
2018-10-26 09:56:19.889  INFO 7536 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2018-10-26 09:56:19.919  INFO 7536 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-10-26 09:56:19.920  INFO 7536 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-10-26 09:56:19.927  INFO 7536 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-10-26 09:56:19.952  INFO 7536 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-10-26 09:56:19.958  INFO 7536 --- [  restartedMain] com.greenenergy.GreenEnergyApplication   : Started GreenEnergyApplication in 5.487 seconds (JVM running for 6.095)

我的 application.properties 文件:

spring.thymeleaf.cache=false
spring.mvc.locale-resolver=fixed
#spring.mvc.locale=en

spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://ec2-54-246-86-167.eu-west-1.compute.amazonaws.com:5432/d3k8k2dts7f4ih?ssl=true;sslfactory=org.postgresql.ssl.NonValidatingFactory
spring.datasource.username=tizzwuqydagwmm
spring.datasource.password=9a88893d6eed1e5c334c2978735eaa273b0458ceefe18c2a439aaab45af9f72c
spring.datasource.driverClassName=org.postgresql.Driver

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
spring.jpa.generate-ddl=true

spring.jpa.hibernate.ddl-auto=create-drop

我的实体类:

package com.greenenergy.domain;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import org.hibernate.annotations.GenericGenerator;

@Entity
public class Story 

    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "native")
    @GenericGenerator(name = "native", strategy = "native")
    @Id
    private long id;
    private String title;
    private String content;
    private Date posted;
    @ManyToOne
    private Blogger blogger;

    private Story() 

    

    public Story(String title, String content, Date posted, Blogger blogger) 
        super();
        this.title = title;
        this.content = content;
        this.posted = posted;
        this.blogger = blogger;
    

    public long getId() 
        return id;
    

    public void setId(long id) 
        this.id = id;
    

    public String getTitle() 
        return title;
    

    public void setTitle(String title) 
        this.title = title;
    

    public String getContent() 
        return content;
    

    public void setContent(String content) 
        this.content = content;
    

    public Date getPosted() 
        return posted;
    

    public void setPosted(Date posted) 
        this.posted = posted;
    

    public Blogger getBlogger() 
        return blogger;
    

    public void setBlogger(Blogger blogger) 
        this.blogger = blogger;
    

    @Override
    public String toString() 
        return "Story [title=" + title + ", content=" + content + ", posted=" + posted + ", blogger=" + blogger + "]";
    


【问题讨论】:

请为“org.hibernate”启用调试,看看他们是否为您提供了更多信息。 【参考方案1】:

调试日志:

2018-10-26 10:25:56.613 DEBUG 12082 --- [  restartedMain] o.h.p.entity.AbstractEntityPersister     :  Delete 0: delete from blogger where id=?
2018-10-26 10:25:56.642 DEBUG 12082 --- [  restartedMain] o.h.l.p.b.i.spaces.QuerySpacesImpl       : Adding QuerySpace : uid = <gen:0> -> org.hibernate.loader.plan.build.internal.spaces.EntityQuerySpaceImpl@46fc130]
2018-10-26 10:25:56.644 DEBUG 12082 --- [  restartedMain] o.h.p.walking.spi.MetamodelGraphWalker   : Visiting attribute path : age
2018-10-26 10:25:56.644 DEBUG 12082 --- [  restartedMain] o.h.p.walking.spi.MetamodelGraphWalker   : Visiting attribute path : name
2018-10-26 10:25:56.644 DEBUG 12082 --- [  restartedMain] o.h.p.walking.spi.MetamodelGraphWalker   : Visiting attribute path : stories
2018-10-26 10:25:56.649 DEBUG 12082 --- [  restartedMain] o.h.l.p.b.i.spaces.QuerySpacesImpl       : Adding QuerySpace : uid = <gen:1> -> org.hibernate.loader.plan.build.internal.spaces.CollectionQuerySpaceImpl@4106511d]
2018-10-26 10:25:56.652 DEBUG 12082 --- [  restartedMain] o.h.l.p.b.i.spaces.QuerySpacesImpl       : Adding QuerySpace : uid = <gen:2> -> org.hibernate.loader.plan.build.internal.spaces.EntityQuerySpaceImpl@105c3ae5]
2018-10-26 10:25:56.653 DEBUG 12082 --- [  restartedMain] lanBuildingAssociationVisitationStrategy : Building LoadPlan...
2018-10-26 10:25:56.665 DEBUG 12082 --- [  restartedMain] h.l.p.e.i.LoadQueryJoinAndFetchProcessor : processing queryspace <gen:0>
2018-10-26 10:25:56.671 DEBUG 12082 --- [  restartedMain] o.h.l.p.build.spi.LoadPlanTreePrinter    : LoadPlan(entity=com.greenenergy.domain.Blogger)
    - Returns
       - EntityReturnImpl(entity=com.greenenergy.domain.Blogger, querySpaceUid=<gen:0>, path=com.greenenergy.domain.Blogger)
          - CollectionAttributeFetchImpl(collection=com.greenenergy.domain.Blogger.stories, querySpaceUid=<gen:1>, path=com.greenenergy.domain.Blogger.stories)
             - (collection element) CollectionFetchableElementEntityGraph(entity=com.greenenergy.domain.Story, querySpaceUid=<gen:2>, path=com.greenenergy.domain.Blogger.stories.<elements>)
    - QuerySpaces
       - EntityQuerySpaceImpl(uid=<gen:0>, entity=com.greenenergy.domain.Blogger)
          - SQL table alias mapping - blogger0_
          - alias suffix - 0_
          - suffixed key columns - id1_0_0_

【讨论】:

以上是关于在 Spring Boot 2、Hibernate、PostgreSQL 中通过 JDBC 语句执行 DDL 时出错的主要内容,如果未能解决你的问题,请参考以下文章

在 Spring Boot 2、Hibernate、PostgreSQL 中通过 JDBC 语句执行 DDL 时出错

Spring Boot 和 JPA 2.0

Spring Boot 2.5.0、Spring Cloud 2020.0.2 和 Hibernate 5.4.31 - H2 数据库多行插入失败

Spring Boot 2.1 缺少多个 org.hibernate.jpa.event 类

Spring Boot JPA Hibernate - 以毫秒精度存储日期

使用 Spring boot 时的两个版本的 Hibernate