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:ca.usask.gmcte.currimap.action.QuestionManager.java

License:Open Source License

public AnswerOption getAnswerOptionById(int id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from w  w w  .j  a  va 2 s .  c  o  m*/
    AnswerOption toReturn = null;
    try {
        toReturn = (AnswerOption) session.get(AnswerOption.class, id);
        session.getTransaction().commit();
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
    }
    return toReturn;
}

From source file:ca.usask.gmcte.currimap.action.QuestionManager.java

License:Open Source License

public boolean saveResponses(Program p, int courseOffering, TreeMap<String, String[]> responses) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from  w w w.ja v a 2  s  .c o m
    try {
        CourseOffering offering = (CourseOffering) session.get(CourseOffering.class, courseOffering);

        for (String key : responses.keySet()) {
            String questionIdString = key.split("_")[2];
            Question q = (Question) session.get(Question.class, Integer.parseInt(questionIdString));
            String[] responseValues = responses.get(key);
            for (String responseString : responseValues) {

                QuestionResponse response = new QuestionResponse();
                response.setProgram(p);
                response.setCourseOffering(offering);
                response.setQuestion(q);
                response.setResponse(responseString);
                session.save(response);
            }
        }
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        HibernateUtil.logException(logger, e);
        return false;
    }
}

From source file:ca.usask.gmcte.util.HibernateUtil.java

License:Open Source License

private static boolean connectionOkay(SessionFactory factory) {
    try {//  w  w w  .j a  v a  2 s. c o m
        Session session = factory.getCurrentSession();
        session.beginTransaction();
        session.get(Organization.class, -1);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        logger.fatal("ERROR IN connectionOkay ", e);
        if (!emailSent) {
            HTMLTools.sendEmailMessage("guus.v@usask.ca", "ulc_events@usask.ca",
                    "Connection error in Currimap!", "You better go and check it ouT");
            emailSent = true;
        }
        return false;
    }

}

From source file:caipsfa.app.modelo.GestionDiagnostico.java

public boolean deleteDiagnostic(int id) {
    boolean estado = false;
    try {/*from w w w  . j a va2s.  com*/
        SessionFactory sesFact = HibernateUtil.getSessionFactory();
        Session ses = sesFact.openSession();
        Transaction trans = ses.beginTransaction();
        Diagnostico diagnostic = (Diagnostico) ses.get(Diagnostico.class, id);
        ses.delete(diagnostic);
        trans.commit();
        ses.close();
        estado = true;
        return estado;
    } catch (Exception e) {
        System.out.println(e);
        return estado;
    }
}

From source file:caipsfa.app.modelo.GestionDoctores.java

public boolean deleteDoctor(int id) {
    boolean estado = false;
    try {/*from  w  ww.j av a  2 s  . c o m*/
        SessionFactory sesFact = HibernateUtil.getSessionFactory();
        Session ses = sesFact.openSession();
        Transaction trans = ses.beginTransaction();
        Doctores doctors = (Doctores) ses.get(Doctores.class, id);
        ses.delete(doctors);
        trans.commit();
        ses.close();
        estado = true;
        return estado;
    } catch (Exception e) {
        System.out.println(e);
        return estado;
    }
}

From source file:caipsfa.app.modelo.GestionProveedores.java

public boolean deleteProvider(int id) {
    boolean estado = false;
    try {/*  w  w  w  .j a  v  a2s .  com*/
        SessionFactory sesFact = HibernateUtil.getSessionFactory();
        Session ses = sesFact.openSession();
        Transaction trans = ses.beginTransaction();
        Proveedores providers = (Proveedores) ses.get(Proveedores.class, id);
        ses.delete(providers);
        trans.commit();
        ses.close();
        estado = true;
        return estado;
    } catch (Exception e) {
        System.out.println(e);
        return estado;
    }
}

From source file:caipsfa.app.modelo.GestionUnidades.java

public boolean deleteUnit(int id) {
    boolean estado = false;
    try {/*from   w  w  w. j a  v  a 2s .co  m*/
        SessionFactory sesFact = HibernateUtil.getSessionFactory();
        Session ses = sesFact.openSession();
        Transaction trans = ses.beginTransaction();
        Unidades unit = (Unidades) ses.get(Unidades.class, id);
        ses.delete(unit);
        trans.commit();
        ses.close();
        estado = true;
        return estado;
    } catch (Exception e) {
        System.out.println(e);
        return estado;
    }
}

From source file:caipsfa.app.modelo.GestionUsuarios.java

public boolean deleteUser(int id) {
    boolean estado = false;
    try {/* w  ww.jav  a  2 s . c o  m*/
        SessionFactory sesFact = HibernateUtil.getSessionFactory();
        Session ses = sesFact.openSession();
        Transaction trans = ses.beginTransaction();
        Usuarios user = (Usuarios) ses.get(Usuarios.class, id);
        ses.delete(user);
        trans.commit();
        ses.close();
        estado = true;
        return estado;
    } catch (Exception e) {
        System.out.println(e);
        return estado;
    }
}

From source file:Catalogo.editaCatalogo.java

private boolean eliminar(String idCatalogo) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//from   w  ww  .j ava  2 s.c om
        session.beginTransaction();
        actor = (Catalogo) session.get(Catalogo.class, Integer.parseInt(idCatalogo));

        if (actor.getPartidas().isEmpty() == false) {
            session.getTransaction().rollback();
            JOptionPane.showMessageDialog(null,
                    "La descripcin esta en uso una partida no se puede eliminar!");
            return false;
        } else {
            session.delete(actor);
            session.getTransaction().commit();
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
        session.getTransaction().rollback();
        return false;
    } finally {
        if (session.isOpen())
            session.close();
    }
}

From source file:Category.categoryGetter.java

/**
 *
 * @param categoryId/*from w w  w . j  a va2 s  . co m*/
 * @return CategoryName
 */
public static String getCategoryNameById(int categoryId) {
    Session session;
    Category category = new Category();
    try {
        session = HibernateUtil.getSessionFactory().openSession();
        category = (Category) session.get(Category.class, categoryId);
        Hibernate.initialize(category);

    } catch (HibernateException e) {

    }

    return category.getCategoryName();

}