hi i have two entities User and Authority they have many to many relation:
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "user_role", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "authority_id") })
private List<Authority> authorities = new ArrayList<Authority>(0);
when i use FetchType.LAZY and try to get the authorities in user i get the exception:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role
here's how i get the user object:
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
User user = userDao.findUserByEmail(username);
if (user == null)
throw new UsernameNotFoundException("No user with username '"
+ username + "' found!");
return new org.springframework.security.core.userdetails.User(
user.getEmail(), user.getPassword(), true, true, true, true,
setUserAuthorities(user.getAuthorities()));
}
i am using session factory to manage my transactions and @Transactional on the dao method.
so is there's any ideas or solutions for this issue ?