facebook

LazyInitializationException

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #320486 Reply

    Smitht19
    Member

    I 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; 
    #320496 Reply

    cconway
    Member

    I’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.

    http://stackoverflow.com/questions/4377829/lazyinitializationexception-by-using-spring-mvc-with-ajax-json-mappingjackso

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: LazyInitializationException

You must be logged in to post in the forum log in