Skip to content

Instantly share code, notes, and snippets.

@CristianoPassos
Last active November 16, 2018 14:34
Show Gist options
  • Save CristianoPassos/4dbdec2f4dd75b5bfcbf91785d42db55 to your computer and use it in GitHub Desktop.
Save CristianoPassos/4dbdec2f4dd75b5bfcbf91785d42db55 to your computer and use it in GitHub Desktop.
@Entity
@Table
public class Role {
@Id
@GeneratedValue
private Long id;
@ManyToMany
private Collection<User> users;
}
@Entity
@Table
public class User {
@Id
@GeneratedValue
private Long id;
@ManyToMany
private Collection<Role> roles;
public Collection<Role> getRoles() {
return roles;
}
}
@Service
public class MyBusinessService {
@Autowired
private UserRepository userRepository;
public void myBussinessLogic() {
final User user = userRepository.findOne(1L);
final Collection<Role> roles = user.getRoles();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment