Example usage for org.hibernate FetchMode JOIN

List of usage examples for org.hibernate FetchMode JOIN

Introduction

In this page you can find the example usage for org.hibernate FetchMode JOIN.

Prototype

FetchMode JOIN

To view the source code for org.hibernate FetchMode JOIN.

Click Source Link

Document

Fetch using an outer join.

Usage

From source file:com.perceptive.epm.perkolcentral.dataaccessor.EmployeeDataAccessor.java

public ArrayList<Employeegroupmap> getEmployeegroupmapByEmployeeID(String employeeId) throws ExceptionWrapper {
    ArrayList<Employeegroupmap> employeegroupmapArrayList = new ArrayList<Employeegroupmap>();
    try {//from  ww  w .  j a  v  a  2s  .c o m
        DetachedCriteria criteria = DetachedCriteria.forClass(Employeegroupmap.class);
        criteria.createAlias("employee", "emp");
        criteria.add(Restrictions.eq("emp.employeeId", Long.valueOf(employeeId)));
        criteria.setFetchMode("emp", FetchMode.JOIN);
        criteria.setFetchMode("groups", FetchMode.JOIN);
        for (Object item : hibernateTemplate.findByCriteria(criteria)) {
            employeegroupmapArrayList.add((Employeegroupmap) item);
        }
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
    return employeegroupmapArrayList;
}

From source file:com.perceptive.epm.perkolcentral.dataaccessor.EmployeeDataAccessor.java

public ArrayList<Employeelicensemapping> getEmployeeLicenseMapByEmployeeId(String employeeId)
        throws ExceptionWrapper {
    ArrayList<Employeelicensemapping> employeelicensemappingArrayList = new ArrayList<Employeelicensemapping>();
    try {//from w  ww  . j  a  v  a2  s .  c  o m
        DetachedCriteria criteria = DetachedCriteria.forClass(Employeelicensemapping.class);
        criteria.createAlias("employee", "emp");
        criteria.add(Restrictions.eq("emp.employeeId", Long.valueOf(employeeId)));
        criteria.setFetchMode("emp", FetchMode.JOIN);
        criteria.setFetchMode("licensemaster", FetchMode.JOIN);
        for (Object item : hibernateTemplate.findByCriteria(criteria)) {
            employeelicensemappingArrayList.add((Employeelicensemapping) item);
        }
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
    return employeelicensemappingArrayList;
}

From source file:com.perceptive.epm.perkolcentral.dataaccessor.EmployeeDataAccessor.java

public void updateEmployee(EmployeeBO employeeBO) throws ExceptionWrapper {
    try {/*from  w w w.j  ava2  s  . c  o  m*/
        DetachedCriteria criteria = DetachedCriteria.forClass(Employee.class);
        criteria.add(Restrictions.eq("employeeId", Long.parseLong(employeeBO.getEmployeeId())));
        criteria.setFetchMode("employeelicensemappings", FetchMode.JOIN);
        criteria.setFetchMode("employeegroupmaps", FetchMode.JOIN);
        criteria.setFetchMode("employeerolemappings", FetchMode.JOIN);

        Employee employee = (Employee) hibernateTemplate.findByCriteria(criteria).get(0);

        employee.setEmail(employeeBO.getEmail());
        employee.setEmployeeName(employeeBO.getEmployeeName());
        employee.setEmployeeUid(employeeBO.getEmployeeUid());
        employee.setJobTitle(employeeBO.getJobTitle());
        employee.setMobileNumber(employeeBO.getMobileNumber());
        employee.setManager(employeeBO.getManager());
        employee.setManagerEmail(employeeBO.getManagerEmail());
        //employee.setExtensionNum(employeeBO.getExtensionNum());
        //employee.setWorkspace(employeeBO.getWorkspace());
        employee.setIsActive(employeeBO.isActive());
        hibernateTemplate.update(employee);
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
}

From source file:com.perceptive.epm.perkolcentral.dataaccessor.ImageNowLicenseDataAccessor.java

public LinkedHashMap<String, Imagenowlicenses> getAllImageNowLicenses() throws ExceptionWrapper {
    LinkedHashMap<String, Imagenowlicenses> imagenowlicensesLinkedHashMap = new LinkedHashMap<String, Imagenowlicenses>();
    try {//from  w ww .  j  ava 2 s  .c  o  m
        DetachedCriteria criteria = DetachedCriteria.forClass(Imagenowlicenses.class);
        criteria.createAlias("employeeByRequestedByEmployeeId", "emp");
        criteria.createAlias("groups", "group");
        criteria.addOrder(Order.asc("licenseRequestedOn"));
        criteria.setFetchMode("emp", FetchMode.JOIN);
        criteria.setFetchMode("group", FetchMode.JOIN);
        criteria.addOrder(Order.asc("licenseRequestedOn"));
        for (Object item : hibernateTemplate.findByCriteria(criteria)) {
            Imagenowlicenses imagenowlicenses = (Imagenowlicenses) item;
            imagenowlicensesLinkedHashMap.put(imagenowlicenses.getImageNowLicenseRequestId(), imagenowlicenses);
        }
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
    return imagenowlicensesLinkedHashMap;
}

From source file:com.perceptive.epm.perkolcentral.dataaccessor.ImageNowLicenseDataAccessor.java

public LinkedHashMap<String, Imagenowlicenses> getAllImageNowLicensesByRequestor(String employeeUID)
        throws ExceptionWrapper {
    LinkedHashMap<String, Imagenowlicenses> imagenowlicensesLinkedHashMap = new LinkedHashMap<String, Imagenowlicenses>();
    try {//w  w w.j  a  v a2 s  . c om
        DetachedCriteria criteria = DetachedCriteria.forClass(Imagenowlicenses.class);
        criteria.createAlias("employeeByRequestedByEmployeeId", "emp");
        criteria.createAlias("groups", "group");
        criteria.add(Restrictions.eq("emp.employeeUid", employeeUID));
        criteria.addOrder(Order.asc("licenseRequestedOn"));
        criteria.setFetchMode("emp", FetchMode.JOIN);
        criteria.setFetchMode("group", FetchMode.JOIN);
        for (Object item : hibernateTemplate.findByCriteria(criteria)) {
            Imagenowlicenses imagenowlicenses = (Imagenowlicenses) item;
            imagenowlicensesLinkedHashMap.put(imagenowlicenses.getImageNowLicenseRequestId(), imagenowlicenses);
        }
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
    return imagenowlicensesLinkedHashMap;
}

From source file:com.perceptive.epm.perkolcentral.dataaccessor.ImageNowLicenseDataAccessor.java

public Imagenowlicenses getAllImageNowLicensesByRequestId(String requestId) throws ExceptionWrapper {

    try {//from  ww  w .j  av a2 s  . c  o m
        DetachedCriteria criteria = DetachedCriteria.forClass(Imagenowlicenses.class);
        criteria.createAlias("employeeByRequestedByEmployeeId", "emp");
        criteria.createAlias("groups", "group");
        criteria.add(Restrictions.eq("imageNowLicenseRequestId", requestId.trim()));
        criteria.setFetchMode("emp", FetchMode.JOIN);
        criteria.setFetchMode("group", FetchMode.JOIN);

        return (Imagenowlicenses) hibernateTemplate.findByCriteria(criteria).get(0);

    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
}

From source file:com.perceptive.epm.perkolcentral.dataaccessor.LicensePurchaseDataAccessor.java

public ArrayList<Licensepurchase> getAllLicensePurchaseInformation() throws ExceptionWrapper {
    Session session = hibernateTemplate.getSessionFactory().openSession();
    boolean isInTransaction = session.getTransaction() != null;
    Transaction tx = null;/*from   ww  w.ja v a 2 s . c  om*/
    if (!isInTransaction) {
        tx = session.beginTransaction();
    }
    ArrayList<Licensepurchase> licensepurchases = new ArrayList<Licensepurchase>();
    try {
        Criteria criteria = session.createCriteria(Licensepurchase.class);
        criteria.setFetchMode("licensemaster", FetchMode.JOIN);
        for (Object obj : criteria.list()) {
            Licensepurchase licensepurchase = (Licensepurchase) obj;
            licensepurchases.add(licensepurchase);
        }

    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    } finally {
        {
            if (!isInTransaction && tx.isActive()) {
                tx.commit();
            }
            session.close();
        }
    }
    return licensepurchases;
}

From source file:com.pkrete.locationservice.admin.dao.locations.LocationsDaoImpl.java

License:Open Source License

/**
 * Returns the library which locationId matches with the given id number.
 * Initializes areas, collections and shelves related to the given library
 * object, so that the library and the objects related to it can be deleted.
 *
 * @param libraryId locationId that is used for searching
 * @param owner the owner of the object//w  ww . ja v a 2  s  . c  om
 * @return library with the desired locationId or null if matching library
 * doesn't exist
 */
@Override
public Library getLibraryToBeDeleted(int libraryId, Owner owner) {
    DetachedCriteria criteria = DetachedCriteria.forClass(Library.class)
            .add(Restrictions.eq("locationId", libraryId)).add(Restrictions.eq("owner", owner))
            .setFetchMode("areas", FetchMode.JOIN);
    List<Library> list = (List<Library>) getHibernateTemplate().findByCriteria(criteria);
    if (list.isEmpty()) {
        return null;
    }
    Hibernate.initialize(list.get(0).getDescriptions());
    Hibernate.initialize(list.get(0).getNotes());
    Hibernate.initialize(list.get(0).getImage());
    Hibernate.initialize(list.get(0).getMap());
    List<LibraryCollection> collections = list.get(0).getCollections();
    for (LibraryCollection collection : collections) {
        Hibernate.initialize(collection.getShelves());
    }
    return list.get(0);
}

From source file:com.puertobahia.iceberg.dao.impl.UsuarioDAOImpl.java

@Override
public List<Usuario> getAllUsuario() {
    Criteria crit = getSession().createCriteria(Usuario.class);
    crit.setFetchMode("zona", FetchMode.JOIN);
    return crit.list();
}

From source file:com.puertobahia.iceberg.dao.impl.ZonaDAOImpl.java

@Override
public Zona getById(Long id) {
    Criteria crit = getSession().createCriteria(Zona.class);
    crit.add(Restrictions.idEq(id));/*from ww w  .j ava  2 s . co  m*/
    crit.setFetchMode("usuario", FetchMode.JOIN);
    crit.setFetchMode("usuario.empleado", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    crit.setFetchMode("consejos_comunitario", FetchMode.JOIN);
    crit.createAlias("consejos_comunitario", "consejo", JoinType.LEFT_OUTER_JOIN);
    crit.add(Restrictions.or(Restrictions.and(Restrictions.eq("consejo.estado", 0)),
            Restrictions.isNull("consejo.estado")));
    return (Zona) crit.uniqueResult();
    /*Criteria crit = getSession().createCriteria(Zona.class);
     crit.add(Restrictions.idEq(id));
     crit.setFetchMode("usuario", FetchMode.JOIN);
     crit.setFetchMode("usuario.empleado", FetchMode.JOIN);
     crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
     Zona zona = (Zona) crit.uniqueResult();
     Criteria crit2 = getSession().createCriteria(ConsejoComunitario.class);
     zona.setConsejos_comunitario(crit2.add(Restrictions.and(Restrictions.idEq(zona.getId()),Restrictions.eq("estado", 0))).list());
     return zona;*/
}