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.OrganizationManager.java

License:Open Source License

public boolean saveOrganizationOutcomeDescriptionById(String value, int organizationOutcomeId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//  w w w  .  ja  v a2  s. c o  m
    try {
        OrganizationOutcome o = (OrganizationOutcome) session.get(OrganizationOutcome.class,
                organizationOutcomeId);
        o.setDescription(value);
        session.merge(o);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

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

License:Open Source License

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

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

License:Open Source License

public boolean removeAttribute(int toRemoveId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();// w w w .j av  a 2 s  .  c  om
    try {
        @SuppressWarnings("unchecked")
        List<InstructorAttributeValue> existing = (List<InstructorAttributeValue>) session
                .createQuery("FROM InstructorAttributeValue WHERE attribute.id = :attrId")
                .setParameter("attrId", toRemoveId).list();
        for (InstructorAttributeValue toDel : existing) {
            session.delete(toDel);
        }
        InstructorAttribute o = (InstructorAttribute) session.get(InstructorAttribute.class, toRemoveId);
        session.delete(o);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

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

License:Open Source License

public boolean removeAttributeValue(int toRemoveId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from w w  w . j ava 2  s.  c o m*/
    try {
        InstructorAttributeValue o = (InstructorAttributeValue) session.get(InstructorAttributeValue.class,
                toRemoveId);
        session.delete(o);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

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

License:Open Source License

public boolean removeCourseAttribute(int toRemoveId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from w w w.j  a va 2 s . co m
    try {
        @SuppressWarnings("unchecked")
        List<CourseAttributeValue> existing = (List<CourseAttributeValue>) session
                .createQuery("FROM CourseAttributeValue WHERE attribute.id = :attrId")
                .setParameter("attrId", toRemoveId).list();
        for (CourseAttributeValue toDel : existing) {
            session.delete(toDel);
        }
        CourseAttribute o = (CourseAttribute) session.get(CourseAttribute.class, toRemoveId);
        session.delete(o);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

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

License:Open Source License

public boolean removeCourseAttributeValue(int toRemoveId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();// w  ww.  j a v  a2s  .c om
    try {
        CourseAttributeValue o = (CourseAttributeValue) session.get(CourseAttributeValue.class, toRemoveId);
        session.delete(o);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

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

License:Open Source License

public boolean removeOrganizationOutcome(int outcomeLinkId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//w  w w . j  av a  2s  .c o m
    try {
        LinkOrganizationOrganizationOutcome l = (LinkOrganizationOrganizationOutcome) session
                .get(LinkOrganizationOrganizationOutcome.class, outcomeLinkId);
        session.delete(l);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

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

License:Open Source License

public boolean removeLinkProgramOutcomeOrganizationOutcome(int id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*w ww .  ja v a  2 s.  c om*/
    try {
        LinkProgramOutcomeOrganizationOutcome l = (LinkProgramOutcomeOrganizationOutcome) session
                .get(LinkProgramOutcomeOrganizationOutcome.class, id);
        session.delete(l);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

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

License:Open Source License

public boolean saveProgramOutcomeOrganizationOutcome(int outcomeId, int organizationOutcomeId, int programId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//  ww w . j  a  v a 2  s . co m
    try {
        LinkProgramOutcomeOrganizationOutcome o = new LinkProgramOutcomeOrganizationOutcome();

        ProgramOutcome outcome = (ProgramOutcome) session.get(ProgramOutcome.class, outcomeId);
        OrganizationOutcome oOutcome = (OrganizationOutcome) session.get(OrganizationOutcome.class,
                organizationOutcomeId);
        Program program = (Program) session.get(Program.class, programId);
        o.setProgram(program);
        o.setProgramOutcome(outcome);
        o.setOrganizationOutcome(oOutcome);
        session.save(o);
        session.getTransaction().commit();
        return true;
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
        try {
            session.getTransaction().rollback();
        } catch (Exception e2) {
            logger.error("Unable to roll back!", e2);
        }
        return false;
    }
}

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

License:Open Source License

public OrganizationOutcome getOrganizationOutcomeById(int id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//  w ww  . j  av  a 2s  . com
    OrganizationOutcome o = null;
    try {
        o = (OrganizationOutcome) session.get(OrganizationOutcome.class, id);
        session.getTransaction().commit();
    } catch (Exception e) {
        HibernateUtil.logException(logger, e);
    }
    return o;
}