List of usage examples for org.hibernate SessionFactory close
void close() throws HibernateException;
From source file:com.mycompany.controllers.ClubController.java
@RequestMapping(value = "/{id}", method = RequestMethod.GET) public String clubPage(@PathVariable("id") String id, Model model) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Klub club = session.find(Klub.class, Integer.parseInt(id)); model.addAttribute("club", club); session.close();/* w w w . j a v a2 s .c o m*/ factory.close(); return "/club/show_club_view"; }
From source file:com.mycompany.controllers.ClubController.java
@RequestMapping(value = "/image/{id}", method = RequestMethod.GET) @ResponseBody// www . ja v a 2s . com public byte[] clubPhoto(@PathVariable("id") String id) throws SQLException { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Klub club = session.find(Klub.class, Integer.parseInt(id)); session.close(); factory.close(); return club.getByteLogo(); }
From source file:com.mycompany.controllers.ClubController.java
@PostMapping("/create") @ResponseBody//w w w .j a v a 2s . c o m public ModelAndView createClub(@Valid ClubForm clubForm, BindingResult result, Model model) throws IOException { if (result.hasErrors()) { return new ModelAndView("redirect:/club/create"); } byte[] bytes; bytes = clubForm.getLogo().getBytes(); bytes = LogoConvertion(bytes); Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); Klub club = new Klub(); club.setNazwa(clubForm.getName()); LobCreator lcreator = Hibernate.getLobCreator(session); Blob blob = (Blob) lcreator.createBlob(bytes); club.setLogo(blob); session.persist(club); t.commit(); session.close(); factory.close(); model.addAttribute("club", club); return new ModelAndView("redirect:/club/" + club.getIdKlub()); }
From source file:com.mycompany.controllers.ClubController.java
@GetMapping("/{id}/edit") public String editClub(ClubForm clubForm, Model model, @PathVariable("id") String id) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Klub club = session.find(Klub.class, Integer.parseInt(id)); model.addAttribute("club", club); session.close();//from w w w. jav a 2 s.com factory.close(); return "/club/edit_club_view"; }
From source file:com.mycompany.controllers.ClubController.java
@PostMapping("/{id}/edit") @ResponseBody// w w w . j a va 2s. co m public ModelAndView editClub(@Valid ClubForm clubForm, BindingResult result, Model model, @PathVariable("id") String id) throws IOException { if (result.hasErrors()) { return new ModelAndView("redirect:/club/" + id + "/edit"); } byte[] bytes; bytes = clubForm.getLogo().getBytes(); bytes = LogoConvertion(bytes); Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); Klub club = session.find(Klub.class, Integer.parseInt(id)); club.setNazwa(clubForm.getName()); LobCreator lcreator = Hibernate.getLobCreator(session); Blob blob = (Blob) lcreator.createBlob(bytes); club.setLogo(blob); session.update(club); t.commit(); session.close(); factory.close(); model.addAttribute("club", club); return new ModelAndView("redirect:/club/" + club.getIdKlub()); }
From source file:com.mycompany.controllers.ClubController.java
@GetMapping("/{id}/remove") public ModelAndView removeClub(Model model, @PathVariable("id") String id) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Transaction t = session.beginTransaction(); Klub club = session.find(Klub.class, Integer.parseInt(id)); session.remove(club);// ww w .j a v a2 s .c om t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/home"); }
From source file:com.mycompany.controllers.LeagueController.java
@RequestMapping(value = "/show/{leagueId}", method = RequestMethod.GET) public String clubPage(@PathVariable("leagueId") String leagueId, Model model) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Liga league = session.find(Liga.class, Integer.parseInt(leagueId)); model.addAttribute("league", league); Query query = session.createQuery("from Druzyna where id_liga=:id"); query.setParameter("id", league.getIdLiga()); List<Druzyna> teamList = query.getResultList(); model.addAttribute("teamList", teamList); session.close();/*from ww w .jav a2 s . c om*/ factory.close(); return "/league/show_concrete_league_view"; }
From source file:com.mycompany.controllers.LeagueController.java
@RequestMapping(value = "/create", method = RequestMethod.POST) public ModelAndView createleague(@Valid LeagueForm leagueForm, Model model) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Transaction t = session.beginTransaction(); Liga league = new Liga(); league.setNazwa(leagueForm.getName()); league.setKraj(leagueForm.getCountry()); session.persist(league);//from w w w .ja va2s.co m t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/leagues/"); }
From source file:com.mycompany.controllers.LeagueController.java
@GetMapping("/edit/{idLeague}") public String editLeague(LeagueForm leagueForm, Model model, @PathVariable("idLeague") String idLeague) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Liga league = session.find(Liga.class, Integer.parseInt(idLeague)); model.addAttribute("league", league); session.close();//from ww w . j a va 2s . c o m factory.close(); return "/league/edit_league_view"; }
From source file:com.mycompany.controllers.LeagueController.java
@PostMapping("/edit/{idLeague}") @ResponseBody//from w w w . j ava 2s . c o m public ModelAndView editLeague(@Valid LeagueForm leagueForm, BindingResult result, Model model, @PathVariable("idLeague") String idLeague) throws IOException { if (result.hasErrors()) { return new ModelAndView("redirect:/league/edit/" + idLeague); } Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); Liga league = session.find(Liga.class, Integer.parseInt(idLeague)); league.setNazwa(leagueForm.getName()); league.setKraj(leagueForm.getCountry()); session.update(league); t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/leagues/"); }