I have the next method in DAO:
public List<Project> getProjects(Category category) {
Session session = sessionFactory.openSession();
session.merge(category);
return category.getProjects();
}
In my application Category is Entity. And Project also. Category has OneToMany relation to Project entity (table). Here I try to get all projects with the same category using this relation (I tried with direct SQL request - it works without problem). When I try to use this method in this way, I got exception
failed to lazily initialize a collection of role: data.Category.project,could not initialize proxy - no Session
I suppose this is because inside method Category is in detached state and I try to make in managed again but with merge command without success((( Or I am wrong. Is it possible to use such code? Not use direct SQL command.