我有两个桌子。其中一项是我关注的数据“事物”。 事物架构:
'thing_type_id'是另一个表的外键,该表基本上充当枚举。
ThingType模式:
我已经为两者创建了类,并且可以使用
@ManyToOne() @JoinColumn(name = "thing_type_id")
private ThingType thingType;
将ThingType对象与每个Thing相关联。但是,唯一相关的字段是ThingType.name。
我想做的是直接引用字符串,例如
@Column(table = "thing_type" name="name")
private String thingType;
我尝试过的方法
@SecondaryTable
批注似乎仅适用于一对一映射。 @JsonIgnore
在ThingType的所有不相关字段上,给我留下了一个仅包含一个条目而不只是该条目值的对象。 谢谢您的帮助!
答案 0 :(得分:0)
弄清楚了。第三种方法有效。
@JsonIgnore @ManyToOne() @JoinColumn(name = "thing_type_id")
private ThingType thingType;
@JsonProperty("thingType")
String getThingType() { return this.thingType.getName(); }