Java ManyTone未使用cascade进行更新
我正在使用Java ManyTone未使用cascade进行更新,java,hibernate,jpa,Java,Hibernate,Jpa,我正在使用hibernate更新manytone关系,但它没有更新子类 class People{ @Id @Column(name = "People_id") @GeneratedValue(generator = "uuid") @GenericGenerator(name = "uuid", strategy = "uuid2") private String id; @NotNull @Size(max = 45)
hibernate
更新manytone
关系,但它没有更新子类
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);
Is未使用区域代码更新区域表
我不确定级联定义是否正确
您能告诉我如何更正吗?请输入您的代码:
people.getRole_id().setRegions_id(people.getRegions_id());
People result = peopleRepository.saveAndFlush(people);
您更新了角色表中的区域id列,但没有区域代码的区域表
您能解释一下您想要做什么吗?无论人们拥有哪个地区,我都会尝试将该地区也放在角色表中,因为这两个表都有这个地区id列。