List of usage examples for org.hibernate SessionFactory close
void close() throws HibernateException;
From source file:com.mpos.controller.ControllerInsert.java
public static void Insertor() { SessionFactory factory = HibernateUtil.getSessionFactory(); Session session = factory.openSession(); Transaction tx = null;//from w w w . j a v a2 s . c o m try { tx = session.beginTransaction(); String sql = "INSERT INTO location (Name,Lat,Lng,ISO,Province) VALUES ('???',???,???,'??','??????')";//write down values you want to enter into the table by following this order SQLQuery query = session.createSQLQuery(sql); query.executeUpdate(); tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); } e.printStackTrace(); } finally { session.close(); factory.close(); // CLOSE CONNECTION } }
From source file:com.mpos.controller.ControllerUpdate.java
public static void Updator() { SessionFactory factory = HibernateUtil.getSessionFactory(); Session session = factory.openSession(); Transaction tx = null;//w w w . jav a2 s.c o m try { tx = session.beginTransaction(); String sql = "UPDATE location SET name='???' WHERE iso = '???' ";//insert position and which values you want to edit from the table SQLQuery query = session.createSQLQuery(sql); query.executeUpdate(); tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); } } finally { session.close(); factory.close(); // CLOSE CONNECTION } }
From source file:com.mycompany.controllers.BoardMemberController.java
@RequestMapping(value = "/create", method = RequestMethod.POST) public ModelAndView createmember(@Valid BoardMemberForm boardMember, @PathVariable("idClub") String idClub, Model model) {/* ww w .j a v a 2 s .c om*/ 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 klub = session.find(Klub.class, Integer.parseInt(idClub)); CzlonekZarzadu member = new CzlonekZarzadu(); member.setImie(boardMember.getFirstName()); member.setNazwisko(boardMember.getLastName()); member.setStanowisko(boardMember.getPosition()); member.setPensja(boardMember.getSalary()); member.setProcentUdzialow(Float.parseFloat(String.valueOf(boardMember.getPercent()))); member.setIdKlub(klub); session.persist(member); t.commit(); session.close(); factory.close(); model.addAttribute("club", idClub); return new ModelAndView("redirect:/club/" + idClub + "/boardmembers/"); }
From source file:com.mycompany.controllers.BoardMemberController.java
@GetMapping("/edit/{idMember}") public String editBoardMember(BoardMemberForm boardMember, Model model, @PathVariable("idClub") String idClub, @PathVariable("idMember") String idMember) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); CzlonekZarzadu member = session.find(CzlonekZarzadu.class, Integer.parseInt(idMember)); model.addAttribute("club", idClub); model.addAttribute("member", member); session.close();/*from www . j a va 2 s.com*/ factory.close(); return "/boardmember/edit_boardmember_view"; }
From source file:com.mycompany.controllers.BoardMemberController.java
@PostMapping("/edit/{idMember}") @ResponseBody//from ww w .j av a2 s . c o m public ModelAndView editBoardMember(@Valid BoardMemberForm boardMember, BindingResult result, Model model, @PathVariable("idClub") String idClub, @PathVariable("idMember") String idMember) throws IOException { if (result.hasErrors()) { return new ModelAndView("redirect:/club/" + idClub + "/boardmembers/edit/" + idMember); } Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); CzlonekZarzadu member = session.find(CzlonekZarzadu.class, Integer.parseInt(idMember)); member.setImie(boardMember.getFirstName()); member.setNazwisko(boardMember.getLastName()); member.setStanowisko(boardMember.getPosition()); member.setPensja(boardMember.getSalary()); member.setProcentUdzialow(Float.parseFloat(String.valueOf(boardMember.getPercent()))); session.update(member); t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + idClub + "/boardmembers/"); }
From source file:com.mycompany.controllers.BoardMemberController.java
@GetMapping("/remove/{idMember}") public ModelAndView removeBoardMember(Model model, @PathVariable("idClub") String idClub, @PathVariable("idMember") String idMember) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Transaction t = session.beginTransaction(); CzlonekZarzadu member = session.find(CzlonekZarzadu.class, Integer.parseInt(idMember)); session.remove(member);/*from w w w .java2 s . c o m*/ t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + idClub + "/boardmembers/"); }
From source file:com.mycompany.controllers.BuildingController.java
@RequestMapping(value = "/edit/{idBuilding}", method = RequestMethod.GET) public String buildingEdit(BuildingForm buildingForm, @PathVariable("idBuilding") String idBuilding, Model model) {// w ww . ja v a2s . co m Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Budynek building = session.find(Budynek.class, Integer.parseInt(idBuilding)); model.addAttribute("building", building); if (building.getBudynekAdministracyjny() != null) { model.addAttribute("bAdmin", building.getBudynekAdministracyjny()); } if (building.getStadion() != null) { model.addAttribute("bArena", building.getStadion()); } if (building.getObiektTreningowy() != null) { model.addAttribute("bTrainingObject", building.getObiektTreningowy()); } session.close(); factory.close(); return "/building/edit_building_view"; }
From source file:com.mycompany.controllers.BuildingController.java
@RequestMapping(value = "/edit/{idBuilding}", method = RequestMethod.POST) public ModelAndView buildingedit(@Valid BuildingForm buildingForm, @PathVariable("idBuilding") String idBuilding, @PathVariable("idClub") String idClub, 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(); Budynek building = session.find(Budynek.class, Integer.parseInt(idBuilding)); if (building.getStadion() != null) { Stadion arena = session.find(Stadion.class, Integer.parseInt(idBuilding)); arena.setDyscyplina(buildingForm.getDiscipline()); arena.setIloscMiejsc(Integer.parseInt(buildingForm.getCapacity())); arena.setNazwa(buildingForm.getName()); session.update(arena);/*from ww w . j a va 2s . c om*/ } if (building.getObiektTreningowy() != null) { model.addAttribute("bTrainingObject", building.getObiektTreningowy()); } building.setKodPocztowy(buildingForm.getPostcode()); building.setMiejscowosc(buildingForm.getCity()); building.setUlicanumer(buildingForm.getStreet()); session.update(building); t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + idClub + "/buildings/"); }
From source file:com.mycompany.controllers.BuildingController.java
@GetMapping("/remove/{idBuilding}") public ModelAndView removeClub(Model model, @PathVariable("idClub") String idClub, @PathVariable("idBuilding") String idBuilding) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Transaction t = session.beginTransaction(); Budynek building = session.find(Budynek.class, Integer.parseInt(idBuilding)); session.remove(building);/*from ww w .ja v a 2 s . co m*/ t.commit(); log.info("dziaa"); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + idClub + "/buildings/"); }
From source file:com.mycompany.controllers.BuildingController.java
@RequestMapping(value = "/create", method = RequestMethod.POST) public ModelAndView createbuilding(@Valid BuildingForm buildingForm, @PathVariable("idClub") String idClub, Model model) {/*from www. j a v a2s. c o m*/ 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 klub = session.find(Klub.class, Integer.parseInt(idClub)); Budynek building = new Budynek(); building.setKodPocztowy(buildingForm.getPostcode()); building.setMiejscowosc(buildingForm.getCity()); building.setUlicanumer(buildingForm.getStreet()); building.setIdKlub(klub); session.persist(building); if (buildingForm.getCapacity() != null) { Stadion arena = new Stadion(building.getIdbudynek()); arena.setDyscyplina(buildingForm.getDiscipline()); arena.setIloscMiejsc(Integer.parseInt(buildingForm.getCapacity())); arena.setNazwa(buildingForm.getName()); arena.setBudynek(building); session.persist(arena); } else if (buildingForm.getDiscipline() != null) { ObiektTreningowy ot = new ObiektTreningowy(building.getIdbudynek()); ot.setBudynek(building); session.persist(ot); } else { BudynekAdministracyjny ba = new BudynekAdministracyjny(building.getIdbudynek()); ba.setBudynek(building); session.persist(ba); } t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + idClub + "/buildings/"); }