hibernate mappin无法确定类型:java.util.List,在表中

时间:2015-11-25 13:01:22

标签: hibernate

运行我的应用程序时遇到以下错误

  

无法确定:java.util.List的类型,在表:Users,for   columns:[org.hibernate.mapping.Column(roles)]

这是我目前的代码,我无法弄清楚为什么会收到此错误

@Entity
@Table(name="Users")
public class UserEntity extends BaseEntity  {


/**
 * 
 */
private static final long serialVersionUID = -8789920463809744548L;

private String firstname;
private String lastname;
private String username;
private String password;
private String role;


@OneToMany(mappedBy="mouad",targetEntity=Role.class)
private List<Role> roles;


public List<Role> getRoles() {
    return roles;
}
public void setRoles(List<Role> roles) {
    this.roles = roles;
}
public String getFirstname() {
    return firstname;
}
public String getRole() {
    return role;
}
public void setRole(String role) {
    this.role = role;
}
public void setFirstname(String firstname) {
    this.firstname = firstname;
}
public String getLastname() {
    return lastname;
}
public void setLastname(String lastname) {
    this.lastname = lastname;
}
public String getUsername() {
    return username;
}
public void setUsername(String username) {
    this.username = username;
}
public String getPassword() {
    return password;
}
public void setPassword(String password) {

     //PasswordEncoder crypto = new Md5PasswordEncoder();
   // this.password = crypto.encodePassword(password, null);
  //  System.out.println(this.password);
    this.password=password;
}

@Entity
@Table(name="Role")
public class Role extends BaseEntity  {
/**
 * 
 */
private static final long serialVersionUID = 1L;



private String rolename;
@ManyToOne(targetEntity = UserEntity.class)
private UserEntity mouad;

public UserEntity getMouad() {
    return mouad;
}

public void setMouad(UserEntity mouad) {
    this.mouad = mouad;
}

public String getRolename() {
    return rolename;
}

public void setRolename(String rolename) {
    this.rolename = rolename;
}
}

什么可能导致此错误发生?任何帮助或建议都非常感谢!

1 个答案:

答案 0 :(得分:0)

删除@ManyToOne和@OneToMany

上的targetEntity

尝试替代父

@OneToMany(mappedBy="mouad")

对于孩子

@ManyToOne
@JoinColumn(name = "<FOREIGN_KEY>")