In my spring project, I have this method in my Dao class to return a List of all rows from a table:
@SuppressWarnings("unchecked") @Transactional public List<E> findAll() { try { List<E> instance = sessionFactory.getCurrentSession().createCriteria(entity.getClass()).list(); System.out.println("returned instance with "+instance.size()+" items"); return instance; } catch (RuntimeException re) { System.out.println("returned null"); return null; } } this method is called from this method from my service class:
@PreAuthorize("hasPermission(#user, 'listagem_'+#this.this.name)") @Transactional public List<E> listagem() { return dao.findAll(); } and this last one it's called from this method from my controller:
@RequestMapping(value="listagem/{pagina}/{items}/{ordem}") @PreAuthorize("hasPermission(#user, 'listagem_'+#this.this.name)") public ModelAndView listagem(@PathVariable("pagina") String pagina, @PathVariable("items") String items, @PathVariable("ordem") String ordem) { ModelAndView mav = new ModelAndView(); mav.setViewName("privado/"+this.getName()+"/listagem"); mav.addObject("lista", serv.listagem()); mav.addObject("pagina", pagina); mav.addObject("items", items); mav.addObject("ordem", ordem); return mav; } @RequestMapping(value="listagem.json", method=RequestMethod.GET) @PreAuthorize("hasPermission(#user, 'listagem_'+#this.this.name)") public ModelAndView listagem_json(@RequestParam("pagina") String pagina, @RequestParam("items") String items, @RequestParam("ordem") String ordem) { ModelAndView mav = new ModelAndView(); mav.setViewName(this.getName()+"/listagem"); mav.addObject("lista", serv.listagem()); mav.addObject("pagina", pagina); mav.addObject("items", items); mav.addObject("ordem", ordem); return mav; } the problem it's the method findAll from Dao class it's returning zero elements, despite the fact I make sure the table in database is populated with at least one row.
Anyone can see what's wrong here? I used the same code in other projects, and worked with no problems. This current project it's the first I am using this generic Dao class with the generic controller and service classes.