我有一個多對一的關係:A * < - >圖1B和欲反序列化從具有乙的主鍵(乙一個JSON甲存在於分貝與該主鍵):反序列化外鍵
{
"b": 1
}
我曾嘗試以下:
@Entity
@Table(name = "table_a")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class A implements Serializable {
@JsonIgnore
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "b", unique = true, nullable = false)
private B b;
}
和
@Entity
@Table(name = "table_b")
public class B implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@OneToMany(mappedBy = "b")
private List<A> a = new ArrayList<>();
}
但對象甲與b = null
創建。我如何反序列化A與b屬性正確實例化從數據庫?
注意:我正在使用傑克遜版本2.6.1。
你想從B信息在哪裏?在數據庫中查看和創建自定義對象,或者只是創建與id字段空? – varren