2

I am using CascadeType.MERGE but the generated sql does not contain any ON UPDATE in the foreign key. Here is my code

@Entity
public class Address {
    @Id
    private int id;

    private String address;
}

@Entity
public class Employee {
    @Id
    private int empId;

    @OneToOne(cascade = CascadeType.MERGE)
    private Address address;
}

Is there anything missing here

Srinivas
  • 390
  • 2
  • 11

1 Answers1

1

CascadeType.MERGE is a JPA construct that tells the provider what when you call merge on Employee to also call merge on the referenced Address.

ON UPDATE CASCADE is a database setting that doesn't seem to have anything to do with CascadeType.merge. It causes the database to update foreign keys if the referenced primary key changes. Since changing primary keys in JPA is not allowed, this setting doesn't make sense. It is recommended you use sequencing for unique identifiers if you have a natural pk that might need to change.

Chris
  • 20,138
  • 2
  • 29
  • 43