我在執行插入操作時收到“錯誤:關系“hibernate_sequence”不存在”例外。
Technical Stack
-> Springboot
-> Hibernate
-> PostgreSQL
Approaches tried so far.
-> Verified all entity classes in project, generation strategy is used as "@GeneratedValue(strategy = GenerationType.IDENTITY)".
-> Verified database tables, pk is either Serial or Int with proper sequence generated value.
-> Tried with use-new-id-generator-mappings property as false, didn't worked.
-> Verified sequence with name "hibernate_sequence" is available in Database.
Analysis so far
-> Entities those are annotated with @Audited having this issue as hibernate envers expect global "hibernate_sequence". But not able to find the exact solution.
Note : This was working few days back without any issue, Since last week started getting this issue.
uj5u.com熱心網友回復:
正如你所說,hibernate-envers 正在尋找hibernate_sequence.
它用于將記錄插入 REVINFO 表
假設spring.jpa.hibernate.ddl-auto未設定為create
任何一個
- 手動創建一個hibernate_sequence
- 使用您想要的名稱創建一個序列。例如
rev_id_seq。然后通過添加 RevisionEntity 的定義來覆寫 REVINFO 定義以更改序列名稱
@Entity
@RevisionEntity
public class MyRevision implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "rev_id_generator")
@SequenceGenerator(name = "rev_id_generator", sequenceName = "rev_id_seq", allocationSize = 1)
@RevisionNumber
private int id;
@RevisionTimestamp
private long timestamp;
// Getters, setters, equals, hashCode ...
}
https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#envers-tracking-modified-entities-revchanges
https://thorben-janssen.com/hibernate-envers-extend-standard-revision/
uj5u.com熱心網友回復:
初始設定 spring.jpa.hibernate.ddl-auto 為第一次創建并運行應用程式。它將創建休眠序列。之后將 spring.jpa.hibernate.ddl-auto 更改為 none。它將防止表中的任何進一步資料丟失。或者您可以根據需要設定更新。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/416533.html
標籤:
下一篇:搜索字串以查找陣列的所有元素
