在Hibernate中保存枚舉值:故障排除錯誤的列類型
在您的情況下,您將MySQL列定義為枚舉並在Java代碼中創建相應的枚舉。但是,您遇到以下錯誤:“ MyApp中的錯誤列類型。針對列性別。找到:枚舉,預期:整數。”當Hibernate期望性別列是一個整數時,由於枚舉被視為序數或字符串而產生的錯誤,這取決於@enumerereated註釋的規範。 可以解決此問題,您可以使用columndefinition Attribute:
By providing a column definition, you instruct Hibernate not to guess the column type but to adhere to the specified definition.Alternatively, if you're not using Hibernate to generate your schema, you can remove the need for column definition values by setting them to arbitrary values:@Column(columnDefinition = “枚舉('虛擬')”) @enumerated(EnumType.String) 私有ManyValueDenum ManyValueDenum;
以這種方式,您可以確保將枚舉值保留在您的Java枚舉中,同時同步您的liquibase或sql腳本。免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3