在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