Example usage for org.hibernate SessionFactory openSession

List of usage examples for org.hibernate SessionFactory openSession

Introduction

In this page you can find the example usage for org.hibernate SessionFactory openSession.

Prototype

Session openSession() throws HibernateException;

Source Link

Document

Open a Session .

Usage

From source file:getstate.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// www  .j  a  va  2 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");

    PrintWriter out = response.getWriter();

    try {
        SessionFactory sf = NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        //            Transaction tr=ss.beginTransaction();

        Criteria cr = ss.createCriteria(StateMaster.class);
        ArrayList<StateMaster> stlist = (ArrayList<StateMaster>) cr.list();
        System.out.println("Size of State" + stlist.size());
        request.setAttribute("state", stlist);

        String id = request.getParameter("id");
        int i = Integer.parseInt(id);

        if (i == 1) {
            RequestDispatcher rd = request.getRequestDispatcher("customerregistration.jsp");
            rd.forward(request, response);
        } else if (i == 2) {

            RequestDispatcher rd = request.getRequestDispatcher("agentregistration.jsp");
            rd.forward(request, response);
        }

        else if (i == 3) {
            RequestDispatcher rd = request.getRequestDispatcher("property_add.jsp");
            rd.forward(request, response);
        }

        else if (i == 4) {

            Criteria cr2 = ss.createCriteria(AgentDetail.class);

            ArrayList<AgentDetail> adl = (ArrayList<AgentDetail>) cr2.list();

            if (!adl.isEmpty()) {
                request.setAttribute("adl", adl);

            }
            RequestDispatcher rd = request.getRequestDispatcher("agents.jsp");
            rd.forward(request, response);
        } else if (i == 5) {
            RequestDispatcher rd = request.getRequestDispatcher("customerprofile.jsp");
            rd.forward(request, response);
        } else if (i == 6) {
            RequestDispatcher rd = request.getRequestDispatcher("agentprofile.jsp");
            rd.forward(request, response);
        } else if (i == 7) {
            RequestDispatcher rd = request.getRequestDispatcher("trial_area.jsp");
            rd.forward(request, response);

        } else if (i == 8) {
            RequestDispatcher rd = request.getRequestDispatcher("analysis_search.jsp");
            rd.forward(request, response);
        } else if (i == 9) {
            Criteria cr3 = ss.createCriteria(PropDetail.class);

            ArrayList<PropDetail> pdl = (ArrayList<PropDetail>) cr3.list();

            if (!pdl.isEmpty()) {
                request.setAttribute("pdl", pdl);

            }

            RequestDispatcher rd = request.getRequestDispatcher("property_search_1.jsp");
            rd.forward(request, response);
        } else if (i == 10) {
            int pid = Integer.parseInt(request.getParameter("pid"));
            PropDetail pd = (PropDetail) ss.get(PropDetail.class, pid);
            request.setAttribute("pd", pd);
            RequestDispatcher rd = request.getRequestDispatcher("prop_update.jsp");
            rd.forward(request, response);
        }
    }

    catch (Exception e) {
        out.println(e.getMessage());
    }
}

From source file:loginServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();
    //userpass query
    Criteria crit = session.createCriteria(SystemUser.class);
    Criterion cond1 = Restrictions.eq("username", username);
    Criterion cond2 = Restrictions.eq("password", password);
    crit.add(Restrictions.and(cond1, cond2));
    if ((SystemUser) crit.uniqueResult() != null) {
        //redirect positive
        RequestDispatcher rdp = request.getRequestDispatcher("/success.jsp");
        rdp.forward(request, response);/*  w  w  w.  ja  v a2  s.c om*/
    } else {
        //redirect negative 
        RequestDispatcher rdp = request.getRequestDispatcher("/fail.jsp");
        rdp.forward(request, response);
    }
    ;

}

From source file:analysis_criteria.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w w w.jav 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");
    PrintWriter out = response.getWriter();
    try {

        SessionFactory sf = NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        Transaction tr = ss.beginTransaction();

        String prstate = request.getParameter("state");
        String prcity = request.getParameter("city");
        String prarea = request.getParameter("area");
        String ptype = request.getParameter("type");
        String pbhk = request.getParameter("bhk");
        String przip = "";

        System.out.println("bhk is" + pbhk);
        System.out.println("type is" + ptype);

        String state = "";
        Criteria cr = ss.createCriteria(StateMaster.class);
        cr.add(Restrictions.eq("sId", Integer.parseInt(prstate)));
        ArrayList<StateMaster> ar = (ArrayList<StateMaster>) cr.list();
        if (ar.isEmpty()) {

        } else {
            StateMaster sm = ar.get(0);
            state = sm.getSName();

        }

        String city = "";
        Criteria cr2 = ss.createCriteria(CityMaster.class);
        cr2.add(Restrictions.eq("cityId", Integer.parseInt(prcity)));
        ArrayList<CityMaster> ar2 = (ArrayList<CityMaster>) cr2.list();
        System.out.println("----------" + ar2.size());
        if (ar2.isEmpty()) {

        } else {
            city = ar2.get(0).getCityName();
            System.out.println("-------" + city);
        }

        String area = "";
        Criteria cr3 = ss.createCriteria(AreaMaster.class);
        cr3.add(Restrictions.eq("areaId", Integer.parseInt(prarea)));
        ArrayList<AreaMaster> ar3 = (ArrayList<AreaMaster>) cr3.list();
        System.out.println("----------" + ar3.size());
        if (ar3.isEmpty()) {

        } else {
            area = ar3.get(0).getAreaName();
            System.out.println("-------" + area);
        }

        Criteria cr4 = ss.createCriteria(AreaMaster.class);
        cr4.add(Restrictions.eq("areaId", Integer.parseInt(prarea)));
        ArrayList<AreaMaster> ar4 = (ArrayList<AreaMaster>) cr4.list();
        System.out.println("----------" + ar4.size());
        if (ar4.isEmpty()) {

        } else {
            przip = ar4.get(0).getZip();
            System.out.println("-------" + przip);
        }

        out.print("after object 0");

        //            
        //            String s="select * from the_asset_consultancy.Filter_criteria;";
        //            
        //            SQLQuery query=ss.createSQLQuery(s);
        //            List<Filtercriteria> l=query.list();
        //          
        Criteria cr5 = ss.createCriteria(Filtercriteria.class);

        ArrayList<Filtercriteria> l = (ArrayList<Filtercriteria>) cr5.list();

        Filtercriteria old = l.get(0);
        System.out.println("this is old cr id:" + old.getCrId());

        Filtercriteria f = new Filtercriteria();

        f.setCrId(old.getCrId());

        f.setArea(area);

        out.print("after object 1");

        f.setBhk(pbhk);
        f.setType(ptype);
        f.setZip(przip);

        ss.evict(old);
        ss.update(f);

        out.print("after object 2");
        tr.commit();
        out.print("after object 3");

        out.print("after object 4");

        //for trial 
        HadoopProcessingClass.Do_Process();
        RequestDispatcher rd = request.getRequestDispatcher("show_growthrate");
        rd.forward(request, response);

        //Original code
        //            RequestDispatcher rd = request.getRequestDispatcher("analysis_search.jsp");
        //            rd.forward(request, response);

    } catch (HibernateException he) {
        out.print(he.getMessage());
    }
}

From source file:reg_serv_cust.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w  ww . j  a  v  a2  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");
    PrintWriter out = response.getWriter();

    try {

        //out.println("1");
        String fn = request.getParameter("fname");
        String ln = request.getParameter("lname");
        String un = request.getParameter("uname");
        String stateid = request.getParameter("state");

        String cityid = request.getParameter("city");
        String areaid = request.getParameter("area");
        String e = request.getParameter("email");
        String num = request.getParameter("number");
        String p = request.getParameter("pwd");

        //out.print("2");
        //  out.print("ijhdi");
        SessionFactory sf = NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        Transaction tr = ss.beginTransaction();

        //out.print("111");
        Login li = new Login();
        li.setUName(un);
        li.setPwd(p);
        li.setURole("customer");

        //    out.print("22");
        ss.save(li);

        // out.println("3");

        String state = "";
        Criteria cr = ss.createCriteria(StateMaster.class);
        cr.add(Restrictions.eq("sId", Integer.parseInt(stateid)));
        ArrayList<StateMaster> ar = (ArrayList<StateMaster>) cr.list();
        System.out.println("----------" + ar.size());
        if (ar.isEmpty()) {

        } else {
            state = ar.get(0).getSName();
            System.out.println("-------" + ar.get(0));
        }

        String city = "";
        Criteria cr2 = ss.createCriteria(CityMaster.class);
        cr2.add(Restrictions.eq("cityId", Integer.parseInt(cityid)));
        ArrayList<CityMaster> ar2 = (ArrayList<CityMaster>) cr2.list();
        System.out.println("----------" + ar2.size());
        if (ar2.isEmpty()) {

        } else {
            city = ar2.get(0).getCityName();
            System.out.println("-------" + city);
        }

        String area = "";
        Criteria cr3 = ss.createCriteria(AreaMaster.class);
        cr3.add(Restrictions.eq("areaId", Integer.parseInt(areaid)));
        ArrayList<AreaMaster> ar3 = (ArrayList<AreaMaster>) cr3.list();
        System.out.println("----------" + ar3.size());
        if (ar3.isEmpty()) {

        } else {
            area = ar3.get(0).getAreaName();
            System.out.println("-------" + area);
        }

        CustomerDetail cd = new CustomerDetail();
        cd.setUId(li);
        cd.setCFname(fn);
        cd.setCLname(ln);

        cd.setCState(state);
        cd.setCCity(city);
        cd.setCArea(area);

        cd.setCNum(num);
        cd.setCEmail(e);

        ss.save(cd);

        //  out.println("Customer Registered");

        /*
            else if(r.equals(strg2))
            {
                
        AgentDetail ad=new AgentDetail();
        ad.setUId(li);
        ad.setAFname(fn);
        ad.setALname(ln);
        ad.setANo(null);
        ad.setARating(null);
        ad.setAAddress(null);
        ad.setAEmail(e);
                
        ss.save(ad);
        out.println("Agent Registered");
                             
                          
            }
          */

        tr.commit();

        HttpSession session = request.getSession();
        session.setAttribute("user", li);

        RequestDispatcher rd = request.getRequestDispatcher("agent_home.jsp");
        rd.include(request, response);

        // out.println("Registration Complete");

    } catch (Exception ex) {
        out.println(ex.getMessage());
    }
}

From source file:sendmessage.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// www  . j  av  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");

    PrintWriter out = response.getWriter();
    HttpSession hs = request.getSession();
    try {

        Login ln = (Login) hs.getAttribute("user");

        SessionFactory sf = NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        Transaction tr = ss.beginTransaction();

        int gid = Integer.parseInt(request.getParameter("gid"));
        GroupDetail gd = (GroupDetail) ss.get(GroupDetail.class, gid);
        String msg = request.getParameter("message");

        ChatMsg cm = new ChatMsg();
        cm.setGId(gd);
        cm.setMsg(msg);
        cm.setUId(ln);

        cm.setDateTime(new Date(System.currentTimeMillis()));

        ss.save(cm);
        tr.commit();

        //   cm.getDateTime(new Date(System.currentTimeMillis()));
        request.setAttribute("gid", gd.getGId());
        RequestDispatcher rd = request.getRequestDispatcher("GetGroupChatServ");
        rd.forward(request, response);

        System.out.println("Group id is :" + gd.getGId());

    } catch (HibernateException he) {
        System.out.print(he.getMessage());
    }
}

From source file:show_growthrate.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  ww  w .jav  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");
    PrintWriter out = response.getWriter();
    try {

        double yeardiff = 0;
        double starty = 0;
        double finaly = 0;
        double startp = 0;
        double finalp = 0;
        double ratesum = 0;
        double agr = 0;

        get_growth g = new get_growth();
        SessionFactory sf = NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        Transaction tr = ss.beginTransaction();

        Criteria cr = ss.createCriteria(AssetData.class);
        ArrayList<AssetData> list = (ArrayList<AssetData>) cr.list();
        System.out.println("list size" + list.size());
        double[] rate = new double[list.size()];
        AssetData[] adata = new AssetData[list.size()];

        for (int i = 0; i < list.size(); i++) {
            adata[i] = list.get(i);
            starty = Double.parseDouble(adata[i].getStartYear());
            System.out.println("start year:" + starty);

            finaly = Double.parseDouble(adata[i].getFinalYear());
            System.out.println("final year:" + finaly);
            yeardiff = finaly - starty;
            System.out.println("The year diff is" + yeardiff);

            startp = Double.parseDouble(adata[i].getStartPrice());
            System.out.println("The start price is" + startp);

            finalp = Double.parseDouble(adata[i].getFinalPrice());
            System.out.println("The end price is" + finalp);

            rate[i] = g.get_growthrate(startp, finalp, yeardiff);

            System.out.println("rate " + i + " is" + rate[i]);

            ratesum = ratesum + rate[i];

            System.out.println("The rate sum " + i + " is" + ratesum);

        }

        agr = ratesum / list.size();
        out.print("The average annual growth is " + agr + "%.");

        request.setAttribute("percent", agr);

        //recently done
        RequestDispatcher rd = request.getRequestDispatcher("percentage_js.jsp");
        //RequestDispatcher rd = request.getRequestDispatcher("analysis_search.jsp");

        rd.forward(request, response);

        tr.commit();
    } catch (HibernateException he) {
        System.out.println(he.getMessage());
    }
}

From source file:TestEmployee.java

@Test
public void saveEmployee() {
    Configuration config = new Configuration();
    SessionFactory factory = config.configure("hibernate.cfg.xml").buildSessionFactory();
    Session session = factory.openSession();
    Transaction tran = session.beginTransaction();
    Employee entity = new Employee();
    entity.setId(0);//  w  w w.  ja va 2  s  .c o  m
    Education item = new Education();
    item.setId(0);
    item.setEmployeeId(null);
    item.setEducationLevel(null);
    entity.getEducations().add(item);
    Employee data = (Employee) session.get(Employee.class, entity.getId());
    Employee result = (Employee) session.merge(entity);
    System.out.println(result.getId());
    tran.commit();

    //Employee data =(Employee) session.get(Employee.class, 0);
    //Employee employee = (Employee) session.get(Employee.class, 3);
    //System.out.println(employee.getId());

}

From source file:property_update.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// w  ww . j  a va  2s  . com
 *
 * @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, FileUploadException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    HttpSession hs = request.getSession();
    try {
        if (hs.getAttribute("user") != null) {
            Login ln = (Login) hs.getAttribute("user");
            System.out.println(ln.getUId());

            String pradd1 = "";
            String pradd2 = "";
            String prage = "";

            String prbhk = "";
            String prdescrip = "";
            String prprice = "";

            String state = "";
            String city = "";
            String area = "";
            String prname = "";
            String prtype = "";
            String prphoto = "";
            String prphoto1 = "";
            String prphoto2 = "";
            String prphoto3 = "";
            String prfarea = "";
            int prid = 0;

            FileItemFactory factory = new DiskFileItemFactory();
            // Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload(factory);

            //get the list of all fields from request
            List<FileItem> fields = upload.parseRequest(request);
            // iterates the object of list
            Iterator<FileItem> it = fields.iterator();
            //getting objects one by one
            while (it.hasNext()) {
                //assigning coming object if list to object of FileItem
                FileItem fileItem = it.next();
                //check whether field is form field or not
                boolean isFormField = fileItem.isFormField();

                if (isFormField) {
                    //get the filed name 
                    String fieldName = fileItem.getFieldName();

                    if (fieldName.equals("pname")) {
                        //getting value of field
                        prname = fileItem.getString();
                        System.out.println(prname);
                    } else if (fieldName.equals("price")) {
                        //getting value of field
                        prprice = fileItem.getString();
                        System.out.println(prprice);
                    } else if (fieldName.equals("pid")) {
                        prid = Integer.parseInt(fileItem.getString());

                    } else if (fieldName.equals("state")) {
                        state = fileItem.getString();
                    } else if (fieldName.equals("city")) {
                        city = fileItem.getString();
                    } else if (fieldName.equals("area")) {
                        area = fileItem.getString();
                    } else if (fieldName.equals("pbhk")) {
                        prbhk = fileItem.getString();
                        System.out.println(prbhk);
                    } else if (fieldName.equals("pdescription")) {
                        prdescrip = fileItem.getString();
                        System.out.println(prdescrip);

                    } else if (fieldName.equals("ptype")) {
                        prtype = fileItem.getString();
                        System.out.println(prtype);

                    } else if (fieldName.equals("paddress1")) {
                        pradd1 = fileItem.getString();
                        System.out.println(pradd1);
                    } else if (fieldName.equals("paddress2")) {
                        pradd2 = fileItem.getString();
                        System.out.println(pradd2);
                    } else if (fieldName.equals("page")) {
                        prage = fileItem.getString();
                        System.out.println(prage);
                    } else if (fieldName.equals("pfarea")) {
                        prfarea = fileItem.getString();
                        System.out.println(prfarea);
                    } else if (fieldName.equals("prid")) {
                        prid = Integer.parseInt(fileItem.getString());
                        System.out.println("prid is " + prid);
                    }

                } else {

                    String fieldName = fileItem.getFieldName();

                    if (fieldName.equals("pic1")) {
                        //getting name of file
                        prphoto = new File(fileItem.getName()).getName();
                        //get the extension of file by diving name into substring
                        //  String extension=custphoto.substring(custphoto.indexOf(".")+1,custphoto.length());;
                        //rename file...concate name and extension
                        // custphoto=ln.getUId()+"."+extension;
                        try {
                            // FOR UBUNTU add GETRESOURCE  and GETPATH

                            String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/property/";
                            // String filePath=  this.getServletContext().getResource("/images/profilepic").getPath()+"\\";
                            System.out.println("====" + fp);
                            fileItem.write(new File(fp + prphoto));
                        } catch (Exception ex) {
                            out.println(ex.toString());
                        }
                    }

                    if (fieldName.equals("pic2")) {

                        prphoto1 = new File(fileItem.getName()).getName();

                        try {

                            String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/property/";
                            // String filePath=  this.getServletContext().getResource("/images/profilepic").getPath()+"\\";
                            System.out.println("====" + fp);
                            fileItem.write(new File(fp + prphoto1));
                        } catch (Exception ex) {
                            out.println(ex.toString());
                        }
                    }

                    if (fieldName.equals("pic3")) {

                        prphoto2 = new File(fileItem.getName()).getName();

                        try {

                            String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/property/";
                            // String filePath=  this.getServletContext().getResource("/images/profilepic").getPath()+"\\";
                            System.out.println("====" + fp);
                            fileItem.write(new File(fp + prphoto2));
                        } catch (Exception ex) {
                            out.println(ex.toString());
                        }

                    }

                    if (fieldName.equals("pic4")) {
                        prphoto3 = new File(fileItem.getName()).getName();

                        try {

                            String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/property/";
                            // String filePath=  this.getServletContext().getResource("/images/profilepic").getPath()+"\\";
                            System.out.println("====" + fp);
                            fileItem.write(new File(fp + prphoto3));
                        } catch (Exception ex) {
                            out.println(ex.toString());
                        }
                    }
                }
            }

            SessionFactory sf = NewHibernateUtil.getSessionFactory();
            Session ss = sf.openSession();
            Transaction tr = ss.beginTransaction();

            //           String state="";
            //            Criteria cr = ss.createCriteria(StateMaster.class);
            //            cr.add(Restrictions.eq("sId", Integer.parseInt(stateid)));
            //            ArrayList<StateMaster> ar = (ArrayList<StateMaster>)cr.list();
            //            System.out.println("----------"+ar.size());
            //            if(ar.isEmpty()){
            //                
            //            }else{
            //                state = ar.get(0).getSName();
            //                System.out.println("-------"+ar.get(0));
            //            }
            //            
            //            String city="";
            //            Criteria cr2 = ss.createCriteria(CityMaster.class);
            //            cr2.add(Restrictions.eq("cityId", Integer.parseInt(cityid)));
            //            ArrayList<CityMaster> ar2 = (ArrayList<CityMaster>)cr2.list();
            //            System.out.println("----------"+ar2.size());
            //            if(ar2.isEmpty()){
            //                
            //            }else{
            //                city = ar2.get(0).getCityName();
            //                System.out.println("-------"+city);
            //            }
            //            
            //            String area="";
            //            Criteria cr3 = ss.createCriteria(AreaMaster.class);
            //            cr3.add(Restrictions.eq("areaId", Integer.parseInt(areaid)));
            //            ArrayList<AreaMaster> ar3 = (ArrayList<AreaMaster>)cr3.list();
            //            System.out.println("----------"+ar3.size());
            //            if(ar3.isEmpty()){
            //                
            //            }else{
            //                area = ar3.get(0).getAreaName();
            //                System.out.println("-------"+area);
            //            }
            //            
            //       Criteria crr=ss.createCriteria(AgentDetail.class);
            //       crr.add(Restrictions.eq("uId", ln.getUId()));
            //       ArrayList<AgentDetail> arr=(ArrayList<AgentDetail>)crr.list();
            //       if(arr.isEmpty())
            //       {
            //           out.print("array empty");
            //       }
            //       else
            //       {
            //           AgentDetail agd=arr.get(0);
            PropDetail prd = (PropDetail) ss.get(PropDetail.class, prid);
            System.out.println("old object id is " + prd.getPId());
            PropDetail prd1 = new PropDetail();

            prd1.setUId(prd.getUId());
            prd1.setPId(prd.getPId());
            prd1.setPDescription(prdescrip);
            prd1.setPImg1(prphoto1);
            prd1.setPImg2(prphoto2);
            prd1.setPImg3(prphoto3);
            prd1.setPImg4(prphoto);
            prd1.setPAdd1(pradd1);
            prd1.setPAdd2(pradd2);
            prd1.setPAge(Integer.parseInt(prage));
            prd1.setPBhk(prbhk);
            prd1.setPFloor(Integer.parseInt(prfarea));
            prd1.setPGmap(null);
            prd1.setPName(prname);
            prd1.setPPrice(Integer.parseInt(prprice));
            prd1.setPStatus(null);
            prd1.setPCity(city);
            prd1.setPArea(area);
            prd1.setPState(state);
            prd1.setPType(prtype);

            ss.evict(prd);
            ss.update(prd1);
            tr.commit();

            RequestDispatcher rd = request.getRequestDispatcher("getstate?id=9");
            rd.forward(request, response);
        }

    } catch (HibernateException e) {
        out.println(e.getMessage());
    }
}

From source file:fetch_agentfeedback.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w w w  . j  a v  a2  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");

    PrintWriter out = response.getWriter();
    HttpSession hs = request.getSession();
    try {

        AgentDetail ad = (AgentDetail) hs.getAttribute("agentobj");
        System.out.print("agent id is" + ad.getAId());
        SessionFactory sf = util.NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();

        Criteria cr1 = ss.createCriteria(AgentFeedback.class);
        cr1.add(Restrictions.eq("aId", ad));
        ArrayList<AgentFeedback> afl = (ArrayList<AgentFeedback>) cr1.list();

        if (!afl.isEmpty()) {

            // HttpSession hs1=request.getSession();
            System.out.println(afl.size());
            System.out.println("inside the servlet else");
            System.out.println("inside the servlet else11");

            hs.setAttribute("afl", afl);
            System.out.println("inside the servlet else222");

        }

        else {
            System.out.println("no agent feedback found");
            ;
        }

        RequestDispatcher rd = request.getRequestDispatcher("agentdescription.jsp");
        System.out.println("forwarding");
        rd.forward(request, response);

    } catch (HibernateException e) {
        out.print(e.getMessage());
    }
}

From source file:TesteMain.java

public void addPessoa() {

    p1.setNomerazosocial("jose Carlos");
    p1.setApelidofantasia("juninho");
    p1.setCodigo("123");
    p1.setCpfcnpj("38351913812");

    Email e = new Email();
    e.setEmail("jcsj2010@gmail.com");
    p1.getEmails().add(e);/*from   www . jav a  2 s . c o  m*/

    Endereco end = new Endereco();
    end.setBairro("oliveira");
    end.setCidade("ipigua");
    p1.getEnderecos().add(end);
    p1.setStatus(Status.ATIVO);

    System.out.println(p1);
    //System.out.println(p1.getEmailPrincipal().getPessoa());

    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session ss = sf.openSession();
    Transaction tx = ss.beginTransaction();
    //ss.save(p1.getEmailPrincipal());
    //ss.saveOrUpdate(e);
    ss.save(p1);
    tx.commit();
    ss.close();

    System.out.println("ok");
}