List of usage examples for org.hibernate.cfg Configuration configure
@Deprecated public Configuration configure(org.w3c.dom.Document document) throws HibernateException
From source file:ru.apertum.journal.db.HibernateUtil.java
License:Open Source License
private HibernateUtil() { try {/*from ww w .j a v a 2s. c om*/ final Configuration configuration = new Configuration(); configuration.configure("/ru/apertum/journal/cfg/hibernate.cfg.xml"); final Properties prop = new Properties(); final File f = new File("config/journal.properties"); if (f.exists()) { prop.load(new FileInputStream(f)); } configuration.addProperties(prop); final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); } catch (Throwable ex) { // Log exception! throw new ExceptionInInitializerError(ex); } //sessionFactory = new AnnotationConfiguration().addAnnotatedClass(Book.class).buildSessionFactory(); }
From source file:rvg.sots.CoursesEntity.java
public static CoursesEntity getById(Long id) { Configuration c = new Configuration(); c.configure("hibernate.config.xml"); // creating seession factory object SessionFactory factory = c.buildSessionFactory(); // creating session object Session session = factory.openSession(); CoursesEntity result = null;/*from w ww. j a va 2s . c o m*/ result = session.get(CoursesEntity.class, id); session.close(); factory.close(); return result; }
From source file:rvg.sots.CoursesEntity.java
public static List<CoursesEntity> getAll() { Configuration c = new Configuration(); c.configure("hibernate.config.xml"); // creating seession factory object SessionFactory factory = c.buildSessionFactory(); // creating session object Session session = factory.openSession(); org.hibernate.query.Query query = session.createQuery("from CoursesEntity"); java.util.List<CoursesEntity> result = query.list(); session.close();//from www . jav a2s. c om factory.close(); return result; }
From source file:services.HibernateFactory.java
/** * * @return/* w w w. j a v a2 s .c o m*/ * @throws HibernateException */ private static SessionFactory configureSessionFactory() throws HibernateException { Configuration configuration = new Configuration(); configuration.configure("hibernate.cfg.xml"); sessionFactory = configuration.buildSessionFactory(); return sessionFactory; }
From source file:servlet.DeleteSR.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w .ja v a2 s. c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet DeleteSR</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet DeleteSR at " + request.getContextPath() + "</h1>"); // No try catch, I suppose the connexion will be okey... Configuration configuration = new Configuration(); configuration.configure("hibernate.cfg.xml"); StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()); SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build()); Session session = sessionFactory.openSession(); Transaction trans = session.beginTransaction(); try { //String id = request.getParameter("sc_id").trim(); int sId; try { sId = Integer.valueOf(request.getParameter("s_id").trim()); } catch (NumberFormatException ne) { throw new HibernateException(new Throwable("The value isn't a number")); } Query query = session.createQuery("from data.S s where s.id = :anId"); query.setParameter("anId", sId); S s = (S) query.uniqueResult(); if (s == null) { throw new HibernateException(new Throwable("This Service ID doesn't exist")); } Iterator it = s.getSrs().iterator(); while (it.hasNext()) { session.delete((Sr) it.next()); } session.persist(s); trans.commit(); session.close(); out.println("The Service Registery(ies) has(have) been removed !!<br/>"); } catch (HibernateException he) { out.println(he.getMessage() + "<br/>"); //out.println(he.getCause() + "<br/>"); out.println("Failed to delete the Service Registery(ies)...<br/>"); trans.rollback(); session.close(); } out.println("</body>"); out.println("</html>"); } }
From source file:servlet.FindSC.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w. j a v a 2s .c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet FindSC</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet FindSC at " + request.getContextPath() + "</h1>"); // No try catch, I suppose the connexion will be okey... Configuration configuration = new Configuration(); configuration.configure("hibernate.cfg.xml"); StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()); SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build()); Session session = sessionFactory.openSession(); try { String sc_name = '%' + request.getParameter("sc_name").trim() + '%'; Criteria crit = session.createCriteria(Sr.class); crit.add(Restrictions.like("scName", sc_name)); Iterator it = crit.list().iterator(); Set<Sr> srs = new HashSet(); while (it.hasNext()) { srs.add((Sr) it.next()); } request.setAttribute("srs", srs); session.close(); getServletConfig().getServletContext().getRequestDispatcher("/FindSC.jsp").forward(request, response); } catch (HibernateException he) { out.println(he.getMessage() + "<br/>"); session.close(); } out.println("</body>"); out.println("</html>"); } }
From source file:servlet.NewQoso.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//w ww . j a v a 2 s . co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet NewQoso</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet NewQoso at " + request.getContextPath() + "</h1>"); // No try catch, I suppose the connexion will be okey... Configuration configuration = new Configuration(); configuration.configure("hibernate.cfg.xml"); StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()); SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build()); Session session = sessionFactory.openSession(); Transaction trans = session.beginTransaction(); try { Qoso qoso = new Qoso(); session.persist(qoso); trans.commit(); session.close(); out.println("The creation of this Quality of Service Offered has succeded !!<br/>"); } catch (HibernateException he) { out.println(he.getMessage() + "<br/>"); //out.println(he.getCause() + "<br/>"); out.println("The creation of this Quality of Service Offered has failed...<br/>"); trans.rollback(); session.close(); } out.println("</body>"); out.println("</html>"); } }
From source file:servlet.NewS.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w .j a v a 2 s. c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet NewS</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet NewS at " + request.getContextPath() + "</h1>"); // No try catch, I suppose the connexion will be okey... Configuration configuration = new Configuration(); configuration.configure("hibernate.cfg.xml"); StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()); SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build()); Session session = sessionFactory.openSession(); Transaction trans = session.beginTransaction(); try { //String id = request.getParameter("s_id").trim(); String name = request.getParameter("s_name").trim(); Query query = session.createQuery("from data.S s where s.name = :aName"); query.setParameter("aName", name); if ((S) query.uniqueResult() != null) { throw new HibernateException(new Throwable("This Service name already exists")); } S s = new S(); s.setName(name); session.persist(s); trans.commit(); session.close(); out.println("The creation of this Service has succeded !!<br/>"); } catch (HibernateException he) { out.println(he.getMessage() + "<br/>"); //out.println(he.getCause() + "<br/>"); out.println("The creation of this Service has failed...<br/>"); trans.rollback(); session.close(); } out.println("</body>"); out.println("</html>"); } }
From source file:servlet.NewSC.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . ja v a 2 s . co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet NewSC</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet NewSC at " + request.getContextPath() + "</h1>"); // No try catch, I suppose the connexion will be okey... Configuration configuration = new Configuration(); configuration.configure("hibernate.cfg.xml"); StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()); SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build()); Session session = sessionFactory.openSession(); Transaction trans = session.beginTransaction(); try { //String id = request.getParameter("sc_id").trim(); String name = request.getParameter("sc_name").trim(); Query query = session.createQuery("from data.Sc sc where sc.name = :aName"); query.setParameter("aName", name); if ((Sc) query.uniqueResult() != null) { throw new HibernateException(new Throwable("This Service Capability name already exists")); } Sc sc = new Sc(); sc.setName(name); /* if (!id.equals("")) { try { int newId = Integer.valueOf(id); // Search if this id isn't already used Query query = session.createQuery("from data.Sc sc where sc.id = :anId"); query.setParameter("anId", newId); if ((Sc) query.uniqueResult() == null) { // This id doesn't exist yet sc.setId(newId); } else { throw new HibernateException(new Throwable("This ID already exist")); } } catch (NumberFormatException ne) { throw new HibernateException(new Throwable("This ID isn't an integer")); } } */ session.persist(sc); trans.commit(); session.close(); out.println("The creation has succeded !!<br/>"); } catch (HibernateException he) { out.println(he.getMessage() + "<br/>"); //out.println(he.getCause() + "<br/>"); out.println("The creation has failed...<br/>"); trans.rollback(); session.close(); } out.println("</body>"); out.println("</html>"); } }
From source file:servlet.NewSP.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w .j ava2 s.c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet NewSP</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet NewSP at " + request.getContextPath() + "</h1>"); // No try catch, I suppose the connexion will be okey... Configuration configuration = new Configuration(); configuration.configure("hibernate.cfg.xml"); StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()); SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build()); Session session = sessionFactory.openSession(); Transaction trans = session.beginTransaction(); try { Sp sp = new Sp(); session.persist(sp); trans.commit(); session.close(); out.println("The creation of this Service P ?? has succeded !!<br/>"); } catch (HibernateException he) { out.println(he.getMessage() + "<br/>"); //out.println(he.getCause() + "<br/>"); out.println("The creation of this Service P ?? has failed...<br/>"); trans.rollback(); session.close(); } out.println("</body>"); out.println("</html>"); } }