英文:
Jpa Enum error with Smallint type in postgres
问题
我想在我的实体中使用枚举(enum),但是在验证时出现了错误,JPA希望将smallint设置为枚举(enum)。我该如何解决这个问题。
> “架构验证:在表【order】的列[status]中遇到了错误的列类型;发现[int2(Types#SMALLINT)],但期望是[int4(Types#INTEGER)]”点击查看图片描述
英文:
I want to put enum in my entity. But I have an error with validation which JPA wonts smallint set as enum. How I can solve this issue.
> "Schema-validation: wrong column type encountered in column [status] in table [order
]; found [int2 (Types#SMALLINT)], but expecting [int4 (Types#INTEGER)]"[enter image description here]
答案1
得分: 11
在你的实体中,在OrderStatus上添加columnDefinition="int2"。
@Column(name = "status", columnDefinition = "int2")
OrderStatus status;
在spring boot 2.2.10上测试通过。
英文:
Add columnDefinition="int2" at OrderStatus in your entity.
@Column(name = "status", columnDefinition = "int2")
OrderStatus status;
Tested on spring boot 2.2.10
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论