Created
January 9, 2018 11:40
-
-
Save Sam-Kruglov/8ad24b593e2f4ecd8cb8c078d27cefcd to your computer and use it in GitHub Desktop.
User 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 = "users") | |
public class User implements Identifiable<Long> { | |
@Id | |
@GeneratedValue(generator = "SequencePerEntityGenerator") | |
private Long id; // only getter | |
@Column(length = 16, nullable = false, unique = true) | |
private String username; // getter and setter | |
@Column(name = "first_name", nullable = false) | |
private String firstName;// getter and setter | |
@Column(name = "last_name", nullable = false) | |
private String lastName;// getter and setter | |
@ManyToOne(optional = false, fetch = FetchType.LAZY) | |
private Group group;// getter and package-private setter | |
/** | |
* A user may only exist with all first and second names and the username. | |
*/ | |
public User(final String username, final String firstName, final String lastName) { | |
this.username = username; | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
/** | |
* For JPA only. | |
*/ | |
protected User() {} | |
//hashcode & equals | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment