Hi All,
I have the classes as below:
Student -
Code:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String fName;
private String lName;
private String mName;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "id")
private Set<Phone> phones;
Phone - Code:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int phoneId;
private int phoneNumber;
So, my Phone table will have a foreign key referencing to Student table. Now if I do a create, it works fine with each row in the Student and Phone tables.
But if I do an update like say add a mname later on for the student, it creates another row in the phone table with the same data as the first row but now the second row will have reference to the phone table and first row foreign key is null.
I want to keep the above schema as is. I want the row to be created in the Phone table only when there is really a change. How can I achieve this? Please advice.
Thanks