我使用的是Hibernate最终版本5.2.17。
我有一个实体Employee,它扩展了实体Person(在两个实体下面)。当我尝试更新一个employee实例时,抛出异常“密钥'PRIMARY'的重复条目'Test'” 。 当我从实体人中删除注释@IdClass(value = PersonId.class)时,更新工作正常。
当我在休眠模式下调试时,合并对象时,始终将Employee实体视为瞬态。
您能告诉我为什么当我添加@IdClass时我无法更新子实体,并且系统将始终尝试调用插入吗?
@Entity
@IdClass(value = PersonId.class)
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "persons")
@Access(value = AccessType.FIELD)
public class Person {
public Person() {
}
@javax.persistence.Column(name = "name", unique = false, nullable = false, insertable = true, updatable = false, length = 255)
@Id
@Basic(fetch = FetchType.EAGER, optional = false)
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity
@Table(name = "employees")
@Inheritance(strategy = InheritanceType.JOINED)
@Access(value = AccessType.FIELD)
public class Employee extends Person {
private String idEmployee ;
public String getIdEmployee() {
return idEmployee;
}
public void setIdEmployee(String idEmployee) {
this.idEmployee = idEmployee;
}
}