亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

hibernate 生成錯誤的查詢

hibernate 生成錯誤的查詢

鳳凰求蠱 2023-10-13 17:28:59
我是 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以該類的名稱提供其值班級。



查看完整回答
反對 回復 2023-10-13
?
慕婉清6462132

TA貢獻1804條經驗 獲得超2個贊

但是您的內容實體中確實有 content_id 和creation_date,問題實體是從其擴展而來的



查看完整回答
反對 回復 2023-10-13
  • 2 回答
  • 0 關注
  • 175 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號