Created
January 9, 2018 11:43
-
-
Save Sam-Kruglov/ef579eca040cf150805aa121e5341976 to your computer and use it in GitHub Desktop.
Group entity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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