Skip to content

Instantly share code, notes, and snippets.

@Sam-Kruglov
Created January 9, 2018 11:40
Show Gist options
  • Save Sam-Kruglov/8ad24b593e2f4ecd8cb8c078d27cefcd to your computer and use it in GitHub Desktop.
Save Sam-Kruglov/8ad24b593e2f4ecd8cb8c078d27cefcd to your computer and use it in GitHub Desktop.
User entity
@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