Last active
November 16, 2018 14:34
-
-
Save CristianoPassos/4dbdec2f4dd75b5bfcbf91785d42db55 to your computer and use it in GitHub Desktop.
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 | |
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