You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 2+HikariCP报错:未指定对象创建方案,实体类自动创建失效

Fixing Spring Boot 1.5.6 → 2.0.0 Upgrade Issues with PostgreSQL

Hey there, let's work through these problems one by one—Spring Boot 2.0 threw in some breaking changes that trip up a lot of folks coming from 1.5.x. I've debugged similar upgrade headaches before, so here's what you need to do:

1. Fix Entity Auto-Creation & Schema.sql Execution

The biggest gotchas here are default behavior changes in Spring Boot 2.0:

  • Datasource initialization mode: By default, Spring Boot 2.0 only runs schema.sql/data.sql for in-memory databases (like H2). For PostgreSQL, you need to explicitly enable it.
  • JPA auto-ddl setting: For non-embedded databases, spring.jpa.hibernate.ddl-auto now defaults to none (meaning Hibernate won't create tables from your @Entity classes).
  • Hikari configuration structure: Hikari properties moved under a hikari nested node (no longer directly under datasource).
  • JDBC URL property: jdbcUrl from 1.5.x was renamed to jdbc-url.

Update your application.properties like this:

spring:
  datasource:
    driver-class-name: org.postgresql.Driver
    jdbc-url: jdbc:postgresql://localhost:5432/database  # Fixed property name, added host/port for clarity
    username: root
    password: root
    schema: classpath:/db/init/schema.sql
    type: com.zaxxer.hikari.HikariDataSource
    initialization-mode: always  # Enable schema.sql execution for PostgreSQL
    # Hikari properties now nested under hikari
    hikari:
      pool-name: SpringBootHikariCP
      maximum-pool-size: 5
  jpa:
    hibernate:
      ddl-auto: update  # Tell Hibernate to auto-create/update tables from entities
    show-sql: true  # Optional, helps debug table creation
    properties:
      hibernate:
        dialect: org.hibernate.dialect.PostgreSQLDialect  # Ensure proper PostgreSQL dialect

2. Fix PostgreSQL Array Support

If you're trying to create array columns via schema.sql, make sure your SQL uses valid PostgreSQL syntax:

-- Example schema.sql entry for a text array
CREATE TABLE your_table (
  id SERIAL PRIMARY KEY,
  your_array_column TEXT[]
);

If you're mapping array fields in your @Entity classes, you'll need extra Hibernate type support. Spring Boot 2.0 uses Hibernate 5.2, so add this dependency (Maven example):

<dependency>
  <groupId>com.vladmihalcea</groupId>
  <artifactId>hibernate-types-52</artifactId>
  <version>2.10.0</version>
</dependency>

Then annotate your entity's array field correctly:

import com.vladmihalcea.hibernate.type.array.StringArrayType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

@Entity
@TypeDef(name = "string-array", typeClass = StringArrayType.class)
public class YourEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Type(type = "string-array")
    @Column(columnDefinition = "text[]")
    private String[] yourArray;

    // Getters and setters
}

3. Resolve "ERROR: the object creation scheme is not indicated"

This error is almost always a side effect of the configuration issues above:

  • Either Hibernate didn't know how to handle entity table creation (because ddl-auto was set to none by default)
  • Or your schema.sql wasn't executing (because initialization-mode was stuck on embedded)

Once you apply the configuration fixes from step 1, this error should disappear. If it persists, double-check your schema.sql for invalid PostgreSQL syntax or duplicate object names.

内容的提问来源于stack exchange,提问作者JONKI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:22:39