Consider entity
public class User {
...
@OneToMany(cascade = CascadeType.ALL)
List<SocialCredential> credentialsList = new ArrayList<SocialCredential> ();
}
with DAO Implementation method
@Transactional
@Override
public User getUser(long id){
Session s = sessionFactory.getCurrentSession();
User u = (User) s.get(User.class, id);
return u;
}
and Controller
@Controller
public class DummyController {
@Autowired
UserDAO userDAO;
public void anyMethodAccessedByGetORPost(){
User u= userDAO.getUser(1L);
}
}
A simple query for entity User automatically fires query to initialize entity list of SocialCredential ? Ultimately it leads to LazyInitializationException.I came to know to know about OpenSessionInViewInterceptor which can solve the issue.How can I apply the same. I am already following http://www.jroller.com/kbaum/entry/orm_lazy_initialization_with_dao but with no success so far.