1

PS:我使用Hibernate作为JPA vendor,现在报错:</p>

引起:org.hibernate.AnnotationException:com.test.Project 的 referencedColumnNames(manager_id) 引用 com.test.FullTimeEmployee 未映射到单个属性

@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                                                                                


}                                                                                                         
4

1 回答 1

1

试试这个

 @JoinColumns({    
  @JoinColumn(name = "nam1", referencedColumnName = "nam1"),
  @JoinColumn(name = "name2", referencedColumnName = "name2")

})
于 2013-04-27T06:40:22.427 回答