I am using hibernate
to update ManyToOne
relationship, but it is not updating child class.
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;
}
When i am saving people using :-
people.getRole_id().setRegions_id(people.getRegions_id());
People result = peopleRepository.saveAndFlush(people);
Is is not updating the region table with region code.
I am not sure if cascade is define correct or not.
Can you please guide me how to correct it ?