Я работаю над Spring boot Security, и когда я хочу его запустить, я обнаружил ошибку:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: xxxxxxxxxx [java.security.Permission]
Я не знаю, как это исправить, и я новичок в Spring.Спасибо, что читаете и проводите время.
@Entity
@Table(name = "ROLES")
public class Role implements Serializable, GrantedAuthority {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(unique = true)
private String name;
@ManyToMany
@JoinTable(
name = "role_permissions",
joinColumns= {@JoinColumn(name="role_id", referencedColumnName="id")},
inverseJoinColumns= {@JoinColumn(name="permission_id", referencedColumnName="id")}
)
@LazyCollection(LazyCollectionOption.FALSE)
private Set <Permission> permission;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<Permission> getPermission() {
return permission;
}
public void setPermission(Set<Permission> permission) {
this.permission = permission;
}
public Role() {}
public Role(String name) {
this.name = name;
}
@Override
public String getAuthority() {
// TODO Auto-generated method stub
return getName();
}
@Override
public String toString() {
return "Role [id=" + id + ", name=" + name + ", permission=" + permission + "]";
}
}
класс разрешений
@Entity
@Table(name="PERMISSIONS")
public class Permissions implements GrantedAuthority {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(unique = true)
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Permissions() {}
public Permissions( String name) {
this.name = name;
}
@Override
public String getAuthority() {
// TODO Auto-generated method stub
return name;
}
@Override
public String toString() {
return "permissions [id=" + id + ", name=" + name + "]";
}
}