com.github.iintelligas.persist.entity.RoleEntity Maven / Gradle / Ivy
package com.github.iintelligas.persist.entity;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.springframework.security.core.GrantedAuthority;
import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;
@Entity
@Table(name = "role")
public class RoleEntity implements GrantedAuthority {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String description;
@ManyToMany
@JoinTable(
name="role_permission",
joinColumns = {@JoinColumn(name="role_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name="permission_id", referencedColumnName = "id")}
)
@LazyCollection(LazyCollectionOption.FALSE)
private Set permissions;
public RoleEntity() {
}
public RoleEntity(String name) {
this.name = name;
}
public RoleEntity(String name, String description) {
this.name = name;
this.description = description;
}
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 String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Set getPermissions() {
return permissions;
}
public void addPermission(PermissionEntity permissionEntity) {
if(permissions == null) {
permissions = new HashSet<>();
}
permissions.add(permissionEntity);
}
public void setPermissions(Set permissions) {
this.permissions = permissions;
}
@Override
public String getAuthority() {
return getName();
}
@Override
public String toString() {
return "RoleEntity{" +
"id=" + id +
", name='" + name + '\'' +
", description='" + description + '\'' +
'}';
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy