外键具有对对象的隐式引用(@manytomany Hibernate中的错误)

时间:2017-12-30 06:44:26

标签: sql-server spring hibernate jpa

您好,我是Hibernate的初学者,当与员工和他的技能组合进行多种联系时,目前面临一个错误。 Employee Table是ValidUser Table的子类。

@Entity
@Table(name="VALIDUSER")
@Inheritance(strategy=InheritanceType.JOINED)
public class ValidUser {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="USERID")
private Long userId;

我的员工表如下: -

@Entity
@Table(name="EMPLOYEE")
@PrimaryKeyJoinColumn(name="USERID")
public class Employee extends ValidUser{

@Column(name="FIRSTNAME")
private String firstName;

@Column(name="LASTNAME")
private String lastName;

@Column(name="REFERCODE")
private Integer referCode;

@Column(name="ISAPPROVED")
private boolean approved;

@Temporal(TemporalType.DATE)
@Column(name="DATEOFBIRTH")
private Date dateOfBirth;

@OneToMany (mappedBy = "employee",orphanRemoval = true, cascade= CascadeType.ALL)
private Set<EmployeeSkillSet>skillsSet;

技能表是: -

@Entity
@Table(name="VALIDSKILLS")
public class ValidSkills {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="SKILLID")
private Integer id;

@Column(name="SKILLNAME")
private String skillName;

@OneToMany(mappedBy = "skill")
private Set<EmployeeSkillSet>skillsSet;

EmployeeSkillSet表:

@Entity
@Table(name = "EMPLOYEESKILLSET")
public class EmployeeSkillSet {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "EMPSKILLSETID")
private Long empSkillSetId;

@ManyToOne
@JoinColumn(name = "USERID") 
private Employee employee;

@ManyToOne
@JoinColumn(name = "SKILLID")
private ValidSkills skill;

@Column
private int skillLevel;

但在跑步时我面临错误

引起:org.hibernate.tool.schema.spi.SchemaManagementException:无法对JDBC目标执行模式管理[alter table employeeskillset add constraint FKmb3coj44rj4vasva5xe6hvbk8外键(userid)引用员工]

引起:com.microsoft.sqlserver.jdbc.SQLServerException:外键'FKmb3coj44rj4vasva5xe6hvbk8'隐含引用对象'employee',其中没有定义主键。

请帮我解决我的错误。

0 个答案:

没有答案