Jpa在PostgreSQL中使用Smallint类型的枚举错误

huangapple go评论57阅读模式
英文:

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]
Jpa在PostgreSQL中使用Smallint类型的枚举错误

Jpa在PostgreSQL中使用Smallint类型的枚举错误

答案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

huangapple
  • 本文由 发表于 2020年10月11日 20:48:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/64304190.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定