我正在尝试使用Jersey,Gson,JPA构建一个REST应用程序,我想将一个JSON对象放到Postgres的JSON或JSONB数据库字段中.
我尝试过这样的事情:如何在JPA中使用Postgres JSONB数据类型?但我的表看到'VARCHAR'类型而不是'JSONB'.
我的实体:
@Entity
@Table(name = "votes")
public class Votes {
@Id
@GeneratedValue
private int id;
private int idSocialChoice;
@Convert(converter=JsonConverter.class)
private JsonObject vote;
public Votes() {
}
public JsonObject getVote() {
return vote;
}
public void setVote(JsonObject vote) {
this.vote = vote;
}
public int getIdSocialChoice() {
return idSocialChoice;
}
public void setIdSocialChoice(int idSocialChoice) {
this.idSocialChoice = idSocialChoice;
}
Run Code Online (Sandbox Code Playgroud)
我如何插入我的实体:
Votes votes0 = new Votes();
votes0.setIdSocialChoice(3);
JsonObject object = Json.createObjectBuilder().build();
votes0.setVote(object);
List<Votes> listvotes = new …Run Code Online (Sandbox Code Playgroud)