List of usage examples for org.hibernate.cfg Configuration configure
@Deprecated public Configuration configure(org.w3c.dom.Document document) throws HibernateException
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();/* www .j a v a2s . c o m*/ factory.close(); return "/club/edit_club_view"; }
From source file:com.mycompany.controllers.ClubController.java
@PostMapping("/{id}/edit") @ResponseBody// www . java2s .c om 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);/* w ww . j av a 2s.c om*/ t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/home"); }
From source file:com.mycompany.controllers.LeagueController.java
@RequestMapping(value = "/", method = RequestMethod.GET) public String leaguePage(Model model) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); List<Liga> leagueList = session.createCriteria(Liga.class).list(); model.addAttribute("leagueList", leagueList); session.close();//from www . jav a2s . co m return "/league/show_leagues_view"; }
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();// ww w . jav a 2 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);/* w w w . j a v a 2 s .c o 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();// www . j a v a 2 s. co m factory.close(); return "/league/edit_league_view"; }
From source file:com.mycompany.controllers.LeagueController.java
@PostMapping("/edit/{idLeague}") @ResponseBody/* ww w.jav a 2 s. c om*/ 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/"); }
From source file:com.mycompany.controllers.LeagueController.java
@GetMapping("/remove/{idLeague}") public ModelAndView removeLeague(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(); Transaction t = session.beginTransaction(); Liga league = session.find(Liga.class, Integer.parseInt(idLeague)); session.remove(league);// w w w . j a v a 2 s. co m t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/leagues/"); }
From source file:com.mycompany.controllers.MainController.java
@RequestMapping({ "/home", "/" }) public String homePage(Model model) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); List<Klub> clubList = session.createCriteria(Klub.class).list(); model.addAttribute("clubList", clubList); session.close();/*from www.ja v a2 s . co m*/ factory.close(); return "/home_view"; }