User
实体的定义如下:
@Entity
@Table(name = "user_account")
public class User {
public enum Role {
CLIENT,
ADMIN
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "username",nullable = false)
private String username;
@Column(name = "password", nullable = false)
private String password;
@Column(name = "role", nullable = false)
private Role role;
//setters and getters
}
我通过执行SQL,将表中的 role
列添加为枚举类型:
CREATE TYPE role AS ENUM('CLIENT', 'ADMIN');
我的请求体如下:
{
"username": "a",
"password": "your_strong_password",
"role": "CLIENT"
}
但,在保存实体对象时出现了异常:org.postgresql.util.PSQLException: ERROR: column “role” is of type role but expression is of type smallint Hint: You will need to rewrite or cast the expression"。
这个需要怎么解决?