在我看来,以下两种映射方式几乎没有区别。这是一个基于 @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;
}
如果我将Dependent的映射更改为什么会发生呢:
@Entity
public class Dependent {
@EmbeddedId DependentId id;
@ManyToOne
@JoinColumn("empid", insertable=false, updatable=false)
Employee emp;
}
上述两种方法的区别是什么?