PS:我使用Hibernate作为JPA供应商,现在我收到了一个错误:
引起:org.hibernate.AnnotationException:引用com.test.FullTimeEmployee的com.test.Project的referencedColumnNames(manager_id)未映射到单个属性
@Entity
@Table(name = "tb_employee")
@IdClass(EmployeePK.class)
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "employee_type", discriminatorType = DiscriminatorType.STRING)
public class Employee implements Serializable {
@Id
@Column(name = "employee_id", nullable = false, length = 50)
protected String Id;
@Id
@Column(name = "employee_type", nullable = false, length = 50)
protected String type;
public static class EmployeePK implements Serializable {
private String Id;
private String type;
}
}
@Entity
@Table(name = "tb_ft_employee")
@DiscriminatorValue("fulltime")
public class FullTimeEmployee extends Employee {
// some other properties
}
@Entity
@Table(name = "tb_project")
public class Project{
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "manager_id", referencedColumnName = "employee_id", unique = false, nullable = false,
updatable = true)
private FullTimeEmployee manager;
// some other properties
}
答案 0 :(得分:1)
试试这个
@JoinColumns({
@JoinColumn(name = "nam1", referencedColumnName = "nam1"),
@JoinColumn(name = "name2", referencedColumnName = "name2")
})