It seems to me that there is virtually no difference between the below two ways of mapping. Here is an example base on @MapsId javadoc:
// parent entity has simple primary key
@Entity
public class Employee {
@Id long empId;
...
}
// dependent entity uses EmbeddedId for composite key
@Embeddable
public class DependentId {
String name;
long empid; // corresponds to primary key type of Employee
}
@Entity
public class Dependent {
@EmbeddedId DependentId id;
...
@MapsId("empid") // maps the empid attribute of embedded id
@ManyToOne Employee emp;
}
What if I change Dependent's mapping to:
@Entity
public class Dependent {
@EmbeddedId DependentId id;
@ManyToOne
@JoinColumn("empid", insertable=false, updatable=false)
Employee emp;
}
What is the difference of the above two approach?

