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

@Override
public List<Projects> getProjectsPaticipation(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("employees-with-projects");
    //    Employees employee = (Employees) sess.
    //            get(Employees.class, id);
    //   return employee.getParticipate();
    Query query = sess//from www .  j a  v  a 2 s  .c o m
            .createQuery("select empl.Participate from" + " com.mycompany.CRMFly.entities.Employees empl");
    // query.setParameter("code", "7277");
    return query.list();

}

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

@Override
public List<Daily> getTasksForEmployee(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("employees-with-tasks");
    Employees employee = (Employees) sess.get(Employees.class, id);
    return employee.getTasks();
}

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

@Override
public void addEvent(Events event) {
    sessionFactory.getCurrentSession().save(event);

    List<Daily> temp = event.getConnectedTasks();
    List<Projects> temp2 = event.getConnectedProjects();

    if (temp != null && temp.size() != 0) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("events-with-tasks");
        temp = dailyDAO.getFromProxy(temp);
        for (Daily task : temp) {
            task.getEventsConnectedWithTask().add(event);
            dailyDAO.changeTask(task);/*www.  j a va  2s . co  m*/
        }

    }

    if (temp2 != null && temp2.size() != 0) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("events-with-projects");
        temp2 = projectsDAO.getFromProxy(temp2);
        for (Projects project : temp2) {
            project.getEventsConnectedWithProjects().add(event);
            projectsDAO.changeProject(project);
        }

    }

}

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

@Override
public void removeEvent(Events event) {
    if (null != event) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        event = (Events) sess.get(Events.class, event.getId());
        List<Daily> temp = event.getConnectedTasks();
        List<Projects> temp2 = event.getConnectedProjects();

        if (temp != null && temp.size() != 0) {
            sess.enableFetchProfile("events-with-tasks");
            temp = dailyDAO.getFromProxy(temp);
            for (Daily task : temp) {
                task.getEventsConnectedWithTask().remove(event);
                sess.update(task);/* w  ww . j ava 2s  .  c o m*/
            }

        }

        if (temp2 != null && temp2.size() != 0) {
            sess.enableFetchProfile("events-with-projects");
            temp2 = projectsDAO.getFromProxy(temp2);
            for (Projects project : temp2) {
                project.getEventsConnectedWithProjects().remove(event);
                sess.update(project);
            }

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

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

@Override
public List<Daily> getTasksOnEvent(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("events-with-tasks");
    Events event = (Events) sess.get(Events.class, id);
    return event.getConnectedTasks();
}

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

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

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

public List<Events> getEventsForEmployee(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("events-with-tasks");
    sess.enableFetchProfile("events-with-projects");
    List<Events> first = sess.createCriteria(Events.class).createCriteria("connectedTasks")
            .createCriteria("implementer").add(Restrictions.eq("id", id)).list();
    List<Events> second = sess.createCriteria(Events.class).createCriteria("connectedProjects")
            .createCriteria("participants").add(Restrictions.eq("id", id)).list();
    first.addAll(second);/*w  w  w  .j  a  v  a  2 s  .  c  o  m*/
    return first;
}

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

@Transactional
public Set<UserAccount> getUsersForGroup(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("groups-with-users");
    UserGroup group = (UserGroup) sess.get(UserGroup.class, id);
    return group.getAccounts();
}

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

@Transactional
public Set<UserGroup> getGroupsOfUser(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("users-with-groups");
    UserAccount account = (UserAccount) sess.get(UserAccount.class, id);
    return account.getGroups();
}

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

@Transactional
public void addUserToGroup(UserAccount acc, UserGroup group) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("users-with-groups");
    acc = (UserAccount) sess.load(UserAccount.class, acc.getId());
    sess.enableFetchProfile("groups-with-users");
    group = (UserGroup) sess.load(UserGroup.class, group.getId());
    acc.getGroups().add(group);//w  w w . ja v  a  2s . c  o m
    group.getAccounts().add(acc);
    updateUser(acc);
    updateGroup(group);
}