我是 hibernate 和 Data JPA 的新手。我嘗試插入到我的表中,但休眠查詢中有一些列在我的表中不存在,因此會拋出錯誤。實際上,一開始當我運行代碼時,hibernate 將這些額外的列添加到我的表中,然后我將application.properties中的spring.jpa.hibernate.ddl-auto值更改為none,但現在當我從表中刪除這些額外的列時,嘗試插入新記錄我看到這些列位于插入方法中。我的實體類@Entitypublic class Content { @Id @NotNull @GeneratedValue Integer id; //this can be null if it is a question @Column(name = "content_id") Integer content_id; @NotBlank @NotNull @Column(name = "body") String body; @Column(name = "creationDate") Timestamp creationDate; @NotNull @Column(name = "user_id") Integer user_id; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Integer getContent_id() { return content_id; } public void setContent_id(Integer content_id) { this.content_id = content_id; } public String getBody() { return body; } public void setBody(String body) { this.body = body; } public Timestamp getCreationDate() { return creationDate; } public void setCreationDate(Timestamp creationDate) { this.creationDate = creationDate; } public int getUser_id() { return user_id; } public void setUser_id(Integer user_id) { this.user_id = user_id; }}
2 回答

至尊寶的傳說
TA貢獻1789條經驗 獲得超10個贊
經過大量搜索和工作,我發現 hibernate 表列的命名約定是用下劃線分隔單詞,這就是我在 hibernate 生成的查詢中看到這些列的原因。因此,如果您的類中有一個像creationDate這樣的變量,hibernate會嘗試轉換為creation_date,這樣當我在這個方法中更改所有列的名稱時,問題就解決了。另外,dtype列是一種特殊的列,當許多類使用同一個表插入數據時,hibernate將創建它,這是因為為了區分哪個類在表中插入記錄,并且hibernate以該類的名稱提供其值班級。
添加回答
舉報
0/150
提交
取消