Example usage for org.hibernate Session enableFetchProfile

List of usage examples for org.hibernate Session enableFetchProfile

Introduction

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

Prototype

void enableFetchProfile(String name) throws UnknownProfileException;

Source Link

Document

Enable a particular fetch profile on this session.

Usage

From source file:com.mycompany.CRMFly.hibernateAccess.ProjectsDAOImpl.java

@Override
public List<Employees> getParticipants(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("projects-with-employees");
    Projects project = (Projects) sess.get(Projects.class, id);
    return project.getParticipants();
}

From source file:com.mycompany.CRMFly.hibernateAccess.ProjectsDAOImpl.java

@Override
public List<Events> getEvents(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("projects-with-events");
    Projects project = (Projects) sess.get(Projects.class, id);
    return project.getEventsConnectedWithProjects();
}

From source file:com.mycompany.CRMFly.hibernateAccess.ProjectsDAOImpl.java

@Override
public List<ParticipantsInProject> getOrgParticipationInProjects(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("projects-with-organisations");
    Projects project = (Projects) sess.get(Projects.class, id);
    return project.getOrganisationsInProject();
}

From source file:com.mycompany.CRMFly.hibernateAccess.ProjectsDAOImpl.java

public List<Organisations> getOrganisationsForSelectedId(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("projects-with-organisations");
    Organisations client = (Organisations) sess.get(Organisations.class, id);
    List<Organisations> returnList = new ArrayList<Organisations>();
    List<ParticipantsInProject> partyList = client.getParticipateInProjects();
    for (ParticipantsInProject org : partyList) {
        returnList.add(org.getOrganisation());
    }//from   w  w w.jav a2 s  .c om
    return returnList;
}

From source file:com.mycompany.CRMFly.hibernateAccess.ProjectsDAOImpl.java

@Override
public Organisations getOrganisations(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("projects-with-orgs");
    ParticipantsInProject project = (ParticipantsInProject) sess.get(ParticipantsInProject.class, id);
    return project.getOrganisation();
}

From source file:com.mycompany.CRMFly.hibernateAccess.ProjectsDAOImpl.java

public List<Projects> getProjectsForEmployee(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("projects-with-employees");
    return sess.createCriteria(Projects.class).createCriteria("participants").add(Restrictions.eq("id", id))
            .list();/*  w ww.j  a  v  a2  s  . co m*/
}

From source file:com.mycompany.CRMFly.hibernateAccess.ProjectsDAOImpl.java

public List<Projects> getProjectsForEmployeeOnDate(Long id, Date date) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("projects-with-employees");
    return sess.createCriteria(Projects.class).add(Restrictions.le("begin_date", date))
            .add(Restrictions.ge("end_date", date)).createCriteria("participants")
            .add(Restrictions.eq("id", id)).list();
}

From source file:com.mycompany.CRMFly.hibernateAccess.RequestsDAOImpl.java

@Override
public void addRequest(Requests request) {

    sessionFactory.getCurrentSession().save(request);
    List<Contacts> contTemp = request.getContacts();
    List<Products> prodTemp = request.getProducts();

    if (contTemp != null && contTemp.size() != 0) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("requests-with-products");
        contTemp = contactsDAO.getFromProxy(contTemp);
        for (Contacts contact : contTemp) {
            contact.getConnectedRequests().add(request);
            contactsDAO.changeContact(contact);
        }/*from   ww  w.  j a  v  a  2  s. com*/

    }
    if (prodTemp != null && prodTemp.size() != 0) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("requests-with-products");
        prodTemp = productsDAO.getFromProxy(prodTemp);
        for (Products product : prodTemp) {
            product.getRequestsForProduct().add(request);
            productsDAO.changeProduct(product);
        }

    }
}

From source file:com.mycompany.CRMFly.hibernateAccess.RequestsDAOImpl.java

@Override
public void removeRequest(Requests request) {
    if (null != request) {

        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        request = (Requests) sess.get(Requests.class, request.getId());
        List<Contacts> contTemp = request.getContacts();
        List<Products> prodTemp = request.getProducts();

        if (contTemp != null && contTemp.size() != 0) {

            sess.enableFetchProfile("requests-with-products");
            contTemp = contactsDAO.getFromProxy(contTemp);
            for (Contacts contact : contTemp) {
                contact.getConnectedRequests().remove(request);
                sess.update(contact);//from  w  ww. j a  v  a  2 s  .c  o m
            }

        }
        if (prodTemp != null && prodTemp.size() != 0) {
            sess.enableFetchProfile("requests-with-products");
            prodTemp = productsDAO.getFromProxy(prodTemp);
            for (Products product : prodTemp) {
                product.getRequestsForProduct().remove(request);
                sess.update(product);
            }

        }
        sess.update(request);
        sessionFactory.getCurrentSession().delete(request);
    }
}

From source file:com.mycompany.CRMFly.hibernateAccess.RequestsDAOImpl.java

@Override
public List<Contacts> getAllContacts(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("requests-with-contacts");
    Requests request = (Requests) sess.get(Requests.class, id);
    return request.getContacts();
}