2017-01-11 4 views
0

Ich bin mit Mapping-Ausnahme festgefahren. Ich habe viele zu viele Beziehung zwischen Mitarbeiter und Rolle. Hier ist der Code. RollenklasseHibernate: Viele bis viele Zuordnung Ausnahme

@Entity 
@Table(name = "role", catalog = "app") 
public class Role implements java.io.Serializable { 

@GeneratedValue(strategy = IDENTITY) 

@Column(name = "roleId", unique = true, nullable = false) 
private Integer roleId; 

@Column(name = "title", nullable = false, length = 50) 
private String title; 

@ManyToMany(fetch = FetchType.LAZY, mappedBy = "roles") 
private Set<Employee> employees = new HashSet<Employee>(0); 

public Role() { 
} 

public Role(String title) { 
    this.title = title; 
} 

public Role(String title, Set<Employee> employees) { 
    this.title = title; 
    this.employees = employees; 
} 

public Integer getRoleId() { 
    return this.roleId; 
} 

public void setRoleId(Integer roleId) { 
    this.roleId = roleId; 
} 

public String getTitle() { 
    return this.title; 
} 

public void setTitle(String title) { 
    this.title = title; 
} 

public Set<Employee> getEmployees() { 
    return this.employees; 
} 

public void setEmployees(Set<Employee> employees) { 
    this.employees = employees; 
} 

} 

und Klasse Employee

@Entity 
@Table(name = "employee", catalog = "app", uniqueConstraints =  @UniqueConstraint(columnNames = "email")) 
public class Employee implements java.io.Serializable { 

@Id 
@GeneratedValue(strategy = IDENTITY) 
@Column(name = "empId", unique = true, nullable = false) 
private Integer empId; 

@Column(name = "name", nullable = false, length = 100) 
private String name; 

@Column(name = "email", unique = true, nullable = false, length = 50) 
private String email; 

@Column(name = "phone", nullable = false, length = 11) 
private String phone; 

@Column(name = "ip", nullable = false, length = 20) 
private String ip; 

@Column(name = "password", nullable = false, length = 200) 
private String password; 


@ManyToMany(fetch = FetchType.LAZY) 
@JoinTable(name = "employee_role", catalog = "app", joinColumns = { 
     @JoinColumn(name = "empId", nullable = false, updatable = false) }, inverseJoinColumns = { 
       @JoinColumn(name = "roleId", nullable = false, updatable = false) }) 
private Set<Role> roles = new HashSet<Role>(0); 

public Employee() { 
} 


public Integer getEmpId() { 
    return this.empId; 
} 

public void setEmpId(Integer empId) { 
    this.empId = empId; 
} 

public City getCity() { 
    return this.city; 
} 

public void setCity(City city) { 
    this.city = city; 
} 

public Posts getPosts() { 
    return this.posts; 
} 

public void setPosts(Posts posts) { 
    this.posts = posts; 
} 

public Teams getTeams() { 
    return this.teams; 
} 

public void setTeams(Teams teams) { 
    this.teams = teams; 
} 

public String getName() { 
    return this.name; 
} 

public void setName(String name) { 
    this.name = name; 
} 

public String getEmail() { 
    return this.email; 
} 

public void setEmail(String email) { 
    this.email = email; 
} 

public String getPhone() { 
    return this.phone; 
} 

public void setPhone(String phone) { 
    this.phone = phone; 
} 

public String getIp() { 
    return this.ip; 
} 

public void setIp(String ip) { 
    this.ip = ip; 
} 

public String getPassword() { 
    return this.password; 
} 

public void setPassword(String password) { 
    this.password = password; 
} 


public Set<Role> getRoles() { 
    return this.roles; 
} 

public void setRoles(Set<Role> roles) { 
    this.roles = roles; 
} 

} 

ist hier die Ausnahme. Bitte erläutern Sie auch die Ausnahme

org.hibernate.AnnotationException: mappedBy eine unbekannte Zieleinheit Eigenschaft verweisen: org.company.app.models.Role.employees in org.company.app.models.Employee.roles

Was ist falsch?

+0

Sie vermissen eine @Id Anmerkung in Rolle oder ist, dass ein Tippfehler verpassen? –

Antwort

0

Es sieht Sie @Id den Vermerk für Rollenklasse

@Id 
@Column(name = "roleId", unique = true, nullable = false) 
private Integer roleId;