- This topic has 1 reply, 2 voices, and was last updated 13 years, 1 month ago by cconway.
-
AuthorPosts
-
Smitht19MemberI am getting a Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: gov.michigan.mdch.ibs.domain.Users.userRoleses, no session or session was closed. I am using JQUERY for my Ajax to call the controller. The Controler will pass back a JSON object to be render in a div tag on the JSP I know the user bean I am trying to return has 2 children tables. I have included the user bean and the DAO. I have tried the OpenSessionInViewFilter in the web.xml and that is not working. I just wanted to know if you had any ideas.
Thanks Todd
Controller @RequestMapping(value = "/adminSearch", method = RequestMethod.POST) public @ResponseBody List getSearchResults( @RequestParam(value = "id", required = true) String id, @RequestParam(value = "fstname", required = true) String fstname, @RequestParam(value = "lstname", required = true) String lstname, Model model) { //display the printed values System.out.println(); System.out.println("username = " + id); System.out.println("firstname = " + fstname); System.out.println("lastname = " + lstname); List users; HibernateSessionFactory.getSession(); users= usersService.findAllUserss(-1, -1); Hibernate.initialize(users); System.out.println("Here is the size "+users.size()); for(Users user:users){ System.out.println(user.getFirstName()); } return users;
cconwayMemberI’m sorry you’re having this problem. It seems to be a common issue with Ajax and Spring/Hibernate. The easiest solution is to change the fetch type to Eager, but that may not work for your model because it may cause too much unnecessary data to be returned. You’ll have to be the judge of the value of that option.
Here is a post on Stack Overflow that offers a few possible solutions.
-
AuthorPosts