[英]PostgreSQL Spring Boot - hibernate_sequence is not generated
我一直在通過 Stack Overflow 和其他來源進行研究,但無法找到我的問題的答案。
基本上我有一個 Spring 引導應用程序,我正在嘗試將 object 保存到 PostgreSQL 數據庫。 嘗試保存 object 時,我收到 hibernate_sequence 不存在錯誤。
ERROR: relation "<schema>.hibernate_sequence" does not exist
這是我處理 id 生成的實體:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, unique = true)
private Long id;
從我的 application.properties 文件中:
######### uses denoted schema (this schema must exist in db or have a .sql file in resources dir that creates it)
spring.jpa.properties.hibernate.default_schema=cinc_student
######### required to make spring use the schema.sql file in resources dir (if not using this file, this can be removed)
spring.datasource.initialization-mode=always
######### prevents hibernate from recreating unique indexes each time the app is restarted.
spring.jpa.properties.hibernate.schema_update.unique_constraint_strategy=RECREATE_QUIETLY
我在資源下使用 schema.sql 文件,其中包含以下行來創建架構:
CREATE SCHEMA IF NOT EXISTS cinc_student
我有兩個測試數據庫,我將我的應用程序指向本地。 在其中一個數據庫中,模式和 hibernate_sequence 是自動生成的,沒有問題。
在另一個數據庫中,創建了模式但未生成序列。 代碼完全沒有區別,只是指向不同的新創建的空本地數據庫。
誰能解釋一下?
我沒有使用@GenerateSequence,因為我希望它使用應該開箱即用的默認 hibernate_sequence。 我不會創建手動序列。
將以下內容添加到application.properties
。 這將告訴 Spring 使用 Postgre 方言,它將在應用程序啟動時自動創建 hibernate_sequence。
spring.jpa.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.