Это также экземпляр класса Entity:
@Entity
@Table(name = "TBL_ACTIVITY", uniqueConstraints = { @UniqueConstraint(columnNames = "ROLE", name = "ROLE_UN") })
public class Activity implements Serializable, Comparable<Activity> {
private static final long serialVersionUID = 2312346871583335007L;
private Long activityId;
private String role;
private String description;
private Activity parent;
private Set<Group> groups = new HashSet<>(0);
private Set<Activity> children = new HashSet<>(0);
public Activity() {}
public Activity(String role, String description) {
this.role = role;
this.description = description;
}
public Activity(String role, String description, Activity parent) {
this.role = role;
this.description = description;
this.parent = parent;
}
public Activity(String role, String description, Activity parent, Set<Group> groups, Set<Activity> children) {
this.role = role;
this.description = description;
this.parent = parent;
this.groups = groups;
this.children = children;
}
@Id
@SequenceGenerator(name = "FIS_SEQ", sequenceName = "FIS_SEQ")
@GeneratedValue(generator = "FIS_SEQ")
@Column(name = "ACTIVITY_ID", nullable = false, unique = true, precision = 19)
public Long getActivityId() {
return activityId;
}
public void setActivityId(Long activityId) {
this.activityId = activityId;
}
@Column(name = "ROLE", nullable = false, length = 100)
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
@Column(name = "DESCRIPTION", length = 100)
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PARENT_ID")
public Activity getParent() {
return parent;
}
public void setParent(Activity parent) {
this.parent = parent;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent")
public Set<Activity> getChildren() {
return children;
}
public void setChildren(Set<Activity> children) {
this.children = children;
}
@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH} ,fetch = FetchType.LAZY, mappedBy = "activities")
public Set<Group> getGroups() {
return groups;
}
public void setGroups(Set<Group> groups) {
this.groups = groups;
}
@Override
public int compareTo(Activity o) {
return Integer.compare(Integer.valueOf(String.valueOf(this.activityId)), Integer.valueOf(String.valueOf(o.getActivityId())));
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Activity activity = (Activity) o;
return Objects.equals(activityId, activity.activityId) &&
Objects.equals(role, activity.role) &&
Objects.equals(description, activity.description) &&
Objects.equals(parent, activity.parent) &&
Objects.equals(groups, activity.groups) &&
Objects.equals(children, activity.children);
}
@Override
public int hashCode() {
return Objects.hash(activityId, role, description, parent, groups, children);
}
@Override
public String toString() {
return "Activity { " +
"activityId = " + activityId +
", role = '" + role + '\'' +
", description = '" + description + '\'' +
", parent = " + parent +
", groups = " + groups +
", children = " + children +
" }";
}
}