rendered paste bodyHTTP Status 500 - Could not write JSON: failed to lazily initialize a collection of role: web.entity.Boards.childBoxList, could not initialize proxy - no Session (through reference chain: web.entity.Boxes["parentBoard"]->web.entity.Boards["childBoxList"]); nested exception is org.codehaus.jackson.map.JsonMappingException: failed to lazily initialize a collection of role: web.entity.Boards.childBoxList, could not initialize proxy - no Session (through reference chain: web.entity.Boxes["parentBoard"]->web.entity.Boards["childBoxList"])//ajax @RequestMapping (value = "/box/create/{parent}/{parentId}/{boxType}/{boxTitle}", method=RequestMethod.GET) public @ResponseBody Boxes createBox(ModelMap model, @PathVariable(value="parent") String parent, @PathVariable(value="parentId") String parentId, @PathVariable(value="boxType") String boxType, @PathVariable(value="boxTitle") String boxTitle ){ //queue //get user id from session (save id in session first) //verify for privs of user if he can create box or not. //create box in the parent board / box Boxes box = new Boxes(); box.setTitle(boxTitle); box.setType(boxType); if(parent.equals("board")){ box.setIsFirstLevelBox(true); //do this in service rather here. / that is set parent of box. Boards board = new Boards(); board = (Boards)( boardService.getBoardById(Long.valueOf(parentId)) ).getObject(); boxService.setParent(box, board); }else if(parent.equals("box")){ Boxes parentBox = new Boxes(); parentBox = (Boxes)( boxService.getBoxById(Long.valueOf(parentId)) ).getObject(); boxService.setParent(box, parentBox); } Boxes savedBox = (Boxes)boxService.save(box).getObject(); System.out.println("box saved title was "+ savedBox.getTitle()); savedBox.setBoxPrivilegesList(null); savedBox.setChildBoxList(null); savedBox.setCompany(null); savedBox.setDescription(boxTitle); savedBox.setParentBox(null); savedBox.setTaskList(null); savedBox.setUserList(null); return savedBox; }==============@Service@Transactional(readOnly = true)public class BoxesServiceImpl implements BoxesService{@Transactional(readOnly = false) public Boxes setParent(Boxes childBox, Boards parentBoard){ childBox.setParentBoard(parentBoard); return childBox; } @Transactional(readOnly = false) public Boxes setParent(Boxes childBox, Boxes parentBox){ childBox.setParentBox(parentBox); return childBox; } @Transactional(readOnly = false) public ResultImpl getBoardById(Long id){ Boards board = boardDAO.getBoardById(id); if (board != null){ result.setIsSuccessful(true); result.setObject(board); //result.setMessageList(Arrays.asList("error.userCreationErrorUnknown"/*,"string"*/)); }else{ result.setIsSuccessful(false); result.setObject(null); result.setMessageList(Arrays.asList("error.boardCreationErrorUnknown"/*,"string"*/)); } return result; }==============Daopublic Boards getBoardById(Long id){ System.out.println("board id entered for lookup was : "+id); System.out.println("debug --- a"); String queryString = "SELECT board FROM Boards AS board " + "WHERE board.id = :id"; Query query = entityManager.createQuery(queryString); System.out.println("debug --- b"); query.setParameter("id", id); List<?> list = query.getResultList(); System.out.println("board name retrieved is" +((Boards)list.get(0)).getTitle().toString() ); System.out.println("debug --- c"); if(list == null || list.size() == 0) throw new UsernameNotFoundException("Board not found"); Boards boardToBeReturned = (Boards)list.get(0); System.out.println("debug --- d"); System.out.println(boardToBeReturned.getTitle()); return boardToBeReturned;// return (Users)list.get(0); } =================@Entitypublic class Boards { @Id @GeneratedValue private Long id; @OneToMany @JoinTable (name = "boards_childboxes", joinColumns = @JoinColumn(name="boardId"), inverseJoinColumns = @JoinColumn(name="childBoxId") ) private Collection<Boxes> childBoxList = new ArrayList<Boxes>(); @ManyToMany private Collection<BoardPrivileges> boardPrivilegesList = new ArrayList<BoardPrivileges>(); @ManyToMany private Collection <Users> userList = new ArrayList<Users>();@Entitypublic class Boxes { @Id @GeneratedValue private Long id; @ManyToOne private Boards parentBoard; @ManyToOne private Boxes parentBox; // the root box will have parentBox == null; @OneToMany @JoinTable (name = "Boxes_childboxes", joinColumns = @JoinColumn(name="BoxId"), inverseJoinColumns = @JoinColumn(name="childBoxId") ) private Collection<Boxes> childBoxList = new ArrayList<Boxes>(); // the last leaf box will have childBox == null; @OneToMany private Collection<Tasks> taskList = new ArrayList<Tasks>(); @ManyToOne private String type; // vertical / horizontal private String title; @ManyToMany private Collection <Users> userList = new ArrayList<Users>();