我到处都看过,但是我不明白我在做什么错-尝试在表中进行内部联接后出现此异常,这是我得到的错误消息
"IllegalArgumentException occurred calling getter of com.userservice.usermanagement.models.Role2.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.userservice.usermanagement.models.Role2.id"
这些是我的模型: 用户
@Entity
@Table(name = "users")
public class User2 {
/**
* User model
*/
private long id;
private String username;
private String email;
private String password;
private String customername;
private String customerid;
private String description;
private Set<Role2> roles = new HashSet<>();
public User2() {
}
public User2(String username, String email, String customername,String customerid,String description, String password) {
this.username = username;
this.email = email;
this.customername = customername;
this.customerid = customerid;
this.description = description;
this.password = password;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Column(name = "username", nullable = false, length = 1024)
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Column(name = "email", nullable = false, length = 1024)
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(name = "password", nullable = false, length = 1024)
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Column(name = "customername", nullable = false, length = 1024)
public String getCustomername() {
return customername;
}
public void setCustomername(String customername) {
this.customername = customername;
}
@Column(name = "customerid", nullable = false, length = 1024)
public String getCustomerid() {
return customerid;
}
public void setCustomerid(String customerid) {
this.customerid = customerid;
}
@Column(name = "description", nullable = false, length = 1024)
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@ManyToOne(targetEntity = Role2.class)
@JoinColumn(name = "role")
public Set<Role2> getRoles() {
return roles;
}
public void setRoles(Set<Role2> roles) {
this.roles = roles;
}
}
角色
@Entity
@Table(name = "roles")
public class Role2 {
/**
* Model for role with all the attributes
*/
private long id;
private Set<Role2> name;
public Role2() {
}
public Role2(Set<Role2> name) {
this.name = name;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@OneToMany
public Set<Role2> getName() {
return name;
}
public void setName(Set<Role2> name) {
this.name = name;
}
}
我已经花了几个小时了,但我未能真正了解原因。如果有人可以在这里指出问题,我将不胜感激。预先感谢