Skip to content

Instantly share code, notes, and snippets.

@Sam-Kruglov
Created January 9, 2018 11:43
Show Gist options
  • Save Sam-Kruglov/ef579eca040cf150805aa121e5341976 to your computer and use it in GitHub Desktop.
Save Sam-Kruglov/ef579eca040cf150805aa121e5341976 to your computer and use it in GitHub Desktop.
Group entity
@Entity
@Table(name = "groups")
public class Group implements Identifiable<Long> {
@Id
@GeneratedValue(generator = "SequencePerEntityGenerator")
private Long id; // getter
@Column(nullable = false, unique = true)
private String name; // getter and setter
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "group")
private Set<User> users = new HashSet<>(); // addUser, removeUser, getReadOnlyUsers
/**
* A group may only exist with a name.
*/
public Group(final String name) {
this.name = name;
}
/**
* For JPA only.
*/
protected Group() {}
// hashcode & equals
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment