Example usage for org.hibernate Session get

List of usage examples for org.hibernate Session get

Introduction

In this page you can find the example usage for org.hibernate Session get.

Prototype

Object get(String entityName, Serializable id);

Source Link

Document

Return the persistent instance of the given named entity with the given identifier, or null if there is no such persistent instance.

Usage

From source file:abd.p1.bd.UserDAO.java

public Usuario findById(String email) {
    Session s = sf.openSession();
    Transaction tr = s.beginTransaction();
    Usuario resultado = (Usuario) s.get(Usuario.class, email);
    tr.commit();/*from   w  w  w  .  j  av a2 s .com*/
    s.close();

    return resultado;
}

From source file:acc_r3_javier_gonzalez.Modificaciones.java

/**
 * Metodo Para eliminar una cerveza de determinado ID pasado por parametro.
 * @param id (int) - id de la cerveza/*w  w w. j a  v a 2  s  .c om*/
 * @return true si se borr, false si no pudo borrarla.
 */
public static boolean eliminar(int id) {
    boolean exito = false;
    Session s = Conexion.getSession();
    Conexion.transacciona();

    R3Cerveza cerve = (R3Cerveza) s.get(R3Cerveza.class, id);
    if (cerve != null) {
        s.delete(cerve);
        exito = true;
    }
    Conexion.commit();
    Conexion.desconecta();

    return exito;
}

From source file:Action.OrderManagement.java

public String updateProgress() {
    Session s = HibernateUtil.getSession();
    Transaction t = s.beginTransaction();
    //  int itemsProcess=Integer.parseInt(getReq().getParameter("itemsProcess"));
    //  int  pStage=Integer.parseInt(getReq().getParameter("pStage"));

    Product_Processing product_Processing = (Product_Processing) s.get(Product_Processing.class,
            getProcessingStageId());//from   w ww.  java 2 s .  c o m
    product_Processing.setItemsProcessed(getItemsProcessed());
    s.update(product_Processing);

    t.commit();
    return "success";
}

From source file:Action.StockManagement.java

public String addStock() throws NullPointerException {
    Session s = HibernateUtil.getSession();
    Transaction t = s.beginTransaction();

    Supplier_Details supplier_Details;
    Query q1 = s.createQuery(" from Supplier_Details where SupplierId='" + getSupplierId() + "'");
    List<Supplier_Details> data1 = q1.list();
    supplier_Details = new Supplier_Details(getSupplierId(), getSupplierName(), getStreet1(), getStreet2(),
            getCity(), getProvince(), getPincode(), getEmailId(), getContactNo1(), getContactNo2());

    if (data1.isEmpty()) {
        s.save(supplier_Details);/*from  w  w w .j a  v a  2 s .co  m*/
    }

    getReq().setAttribute(getSupplierName(), getResult());

    t.commit();
    Session s1 = HibernateUtil.getSession();
    Transaction t1 = s1.beginTransaction();
    Item_History item_History;
    Query q = s1.createQuery(" from Current_Stock where itemId='" + getItemId() + "'");
    List<Current_Stock> data = q.list();
    if (data.isEmpty()) {
        item_History = new Item_History(0, getName(), getCompanyName(), getQuantity(), getType(),
                getDescription(), getCostPerPiece(), getDateOfPurchase(), supplier_Details);
        Current_Stock current_Stock = new Current_Stock(getItemId(), getName(), getQuantity(),
                getCostPerPiece(), getType(), getDescription());
        s1.save(item_History);
        s1.save(current_Stock);
    } else {
        item_History = new Item_History(0, getName(), getCompanyName(), getQuantity(), getType(),
                getDescription(), getCostPerPiece(), getDateOfPurchase(), supplier_Details);
        Current_Stock current_Stock = (Current_Stock) s1.get(Current_Stock.class, getItemId());
        current_Stock.setQuantity(getQuantity() + current_Stock.getQuantity());
        double newCost = ((current_Stock.getCostPerPiece() * current_Stock.getQuantity()
                + getQuantity() * getCostPerPiece()) / current_Stock.getQuantity() + getQuantity());
        current_Stock.setCostPerPiece(newCost);
        s1.save(item_History);
        s1.save(current_Stock);

    }

    getReq().setAttribute(getSupplierName(), getResult());

    t1.commit();

    return "success";
}

From source file:Activity.activityGetter.java

public static Activity getActivityById(int activityId) {
    Session session;
    Activity activity = new Activity();
    try {// ww w. j  a  v a2s  .co  m
        session = HibernateUtil.getSessionFactory().openSession();

        activity = (Activity) session.get(Activity.class, activityId);
        Hibernate.initialize(activity);
        // List<Category> Categoryresult = criteria.list();

    } catch (HibernateException e) {
        throw e;
    }
    return activity;
}

From source file:Activity.activityGetter.java

public static ActivityReport getActivityReportById(int categoryId) {
    Session session;
    ActivityReport activityReport = new ActivityReport();
    try {/*w ww .  j  a v  a  2 s.  c  o m*/
        session = HibernateUtil.getSessionFactory().openSession();

        activityReport = (ActivityReport) session.get(ActivityReport.class, categoryId);
        Hibernate.initialize(activityReport);
        // List<Category> Categoryresult = criteria.list();

    } catch (HibernateException e) {
        throw e;
    }
    return activityReport;
}

From source file:Activity.activitySetter.java

public static void updateActivityById(Integer activityId, String activityName, Category category) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();/*  w  ww .j  a va  2  s .c o  m*/
    Activity updateAct = new Activity();
    updateAct = (Activity) session.get(Activity.class, activityId);
    Hibernate.initialize(updateAct);
    updateAct.setActivityName(activityName);
    updateAct.setCategory(category);
    session.merge(updateAct);
    session.saveOrUpdate(updateAct);
    session.getTransaction().commit();

}

From source file:Activity.activitySetter.java

public static void updateActivityReportById(Integer activityReportId, Activity activity,
        String activityDescription, Timestamp activityStartTime, Timestamp activityEndTime) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();//from   w  w w. j  av a 2  s . c om
    ActivityReport updateActRep = new ActivityReport();
    updateActRep = (ActivityReport) session.get(ActivityReport.class, activityReportId);
    Hibernate.initialize(updateActRep);
    updateActRep.setActivity(activity);
    updateActRep.setActivityDescription(activityDescription);
    updateActRep.setActivityStartTime(activityStartTime);
    updateActRep.setActivityEndTime(activityEndTime);
    session.merge(updateActRep);
    session.saveOrUpdate(updateActRep);
    session.getTransaction().commit();

}

From source file:admin.CancelFlightHandler.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String flightId = request.getParameter("flightId");
    String message = null;// ww w .  ja  v  a2 s  .  c o  m
    try {
        FlightMaster flight;
        Session session = HibernateDAOLayer.getSession();
        flight = (FlightMaster) session.get(FlightMaster.class, Integer.parseInt(flightId));

        Transaction transaction = session.beginTransaction();
        for (FlightFareMap ffm : flight.getFare()) {
            session.delete(ffm);
        }
        for (CustomerDetails cd : flight.getCustomers()) {
            session.delete(cd);
        }
        session.delete(flight);
        transaction.commit();
        message = "Flight Number " + flightId + " Cancelled Successfully !!!";
    } catch (Exception e) {
        message = "Error : " + e.getMessage();
        request.setAttribute("emessage", message);
        e.printStackTrace();
    } finally {
        request.setAttribute("message", message);
        RequestDispatcher dispatcher = request.getRequestDispatcher("cancelflight.jsp");
        dispatcher.forward(request, response);

    }
}

From source file:agenda_hibernate.controlador.Operaciones.java

public Usuarios buscaUser(String usuario) {
    Usuarios usr;//w  ww .  ja va 2 s  .c  o  m
    SessionFactory sesion = NewHibernateUtil.getSessionFactory();
    Session session;
    session = sesion.openSession();
    Transaction tx = session.beginTransaction();
    usr = (Usuarios) session.get(Usuarios.class, usuario);
    tx.commit();
    session.close();

    return usr;
}