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 asu = (User) s.get(User.class, id);
return asu;
}
and Controller
@Controller
public class DummyController {
@Autowired
UserDAO userDAO;
public void anyMethodAccessedByGetORPost(){
User u= userDAO.getUser(1L);
}
}
My question is why a simple query for entity User automatically fires query to initialize entity list of SocialCredential ? Is there anything wrong with @Transaction.I am not interested to EAGERLY load list SocialCredential.