0

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 ?

KostasC
  • 1,076
  • 6
  • 20
  • 40
Anchit
  • 1

1 Answers1

0

with your code:

people.getRole_id().setRegions_id(people.getRegions_id());
People result = peopleRepository.saveAndFlush(people);

You updated regions_id column in Role table, but not the region table with region code.

Could you explain what you wish to do?

Aleksei
  • 104
  • 8
  • whatever region people has i am trying to put that region in role table as well, as both table have this region id column. – Anchit Oct 13 '15 at 12:40