genechu
genechu

Reputation: 97

JPA(Hibernate) to describe Inheritance and relations to Subclass

PS:I use Hibernate as JPA vendor,now i got an error :

Caused by: org.hibernate.AnnotationException: referencedColumnNames(manager_id) of com.test.Project referencing com.test.FullTimeEmployee not mapped to a single property

@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                                                                                


}                                                                                                         

Upvotes: 1

Views: 161

Answers (1)

samba
samba

Reputation: 2273

try with this

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

})

Upvotes: 1

Related Questions