Last active
May 29, 2019 00:44
-
-
Save BrunoDSouza/13d0122d30bcf6f2772cb4035f4cf2a8 to your computer and use it in GitHub Desktop.
Usuarios&Roles
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="roles") | |
public class Role{ | |
//Contructor | |
public Role(...){}; | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
private Long id; | |
@NotBlank | |
private String descricao; | |
@NotNull | |
private TipoStatus status = TipoStatus.ATIVADO; | |
/*Getters and Setters*/ | |
.... | |
} |
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") | |
@UsersConstraint | |
public class User{ | |
//Constructor | |
public Users(...) {} | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
private Long id; | |
@NotBlank | |
private String username; | |
@NotNull | |
private Date dtNascimento; | |
@NotBlank | |
private String email; | |
@NotBlank | |
private String senha; | |
@NotNull | |
private TipoStatus status = TipoStatus.ATIVADO; | |
@NotNull | |
@OneToMany(cascade = {CascadeType.PERSIST,CascadeType.REFRESH, CascadeType.MERGE}, fetch = FetchType.EAGER, orphanRemoval=false) | |
@JoinTable(name="users_roles", joinColumns = @JoinColumn(name = "userId"), inverseJoinColumns = @JoinColumn(name="roleId")) | |
private Set<Role> roles; | |
/*Getters and Setters*/ | |
.... | |
public Set<Role> getRoles() { return roles; } | |
public void setRoles(Set<Role> roles) { this.roles = roles; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment