0
我正在使用hibernate
更新ManyToOne
關係,但它沒有更新子級。ManyToOne未更新級聯
class People{
@Id
@Column(name = "People_id")
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
private String id;
@NotNull
@Size(max = 45)
@Column(name = "phone", length = 45, nullable = false)
private String phone;
@ManyToOne
@JoinColumn(name="regions_id")
private Regions regionsid;
@ManyToOne
@JoinColumn(name="role_id")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
private Role role_id;
}
class Role {
@Id
@Column(name = "Role_id")
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
private String id;
@ManyToOne
@JoinColumn(name="regions_id")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
private Regions regions_id;
}
public class Regions implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
}
當我使用救人: -
people.getRole_id().setRegions_id(people.getRegions_id());
People result = peopleRepository.saveAndFlush(people);
是不與區域代碼更新區域表。
我不知道級聯是否定義正確與否。
你能指導我如何糾正它嗎?
無論人們有什麼區域,我都試圖將該區域放入角色表中,因爲這兩個表都具有此區域ID列。 – Anchit