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:au.edu.anu.metadatastores.store.digitalcollections.DigitalCollectionsService.java

License:Open Source License

public DigitalCollection getDigitalCollection(String id) {
    Session session = StoreHibernateUtil.getSessionFactory().openSession();
    session.enableFetchProfile("attributes");
    //DublinCore digitalCollection = null;
    try {/*  www. j  a v  a 2 s  .  co m*/
        Query query = session.createQuery("FROM DigitalCollectionItem WHERE extId = :extId");
        query.setParameter("extId", id);

        DigitalCollectionsItem item = (DigitalCollectionsItem) query.uniqueResult();
        //digitalCollection = getDigitalCollection(item);
        return getDigitalCollection(item);
    } finally {
        session.close();
    }

    //return digitalCollection;
}

From source file:au.edu.anu.metadatastores.store.misc.RelationService.java

License:Open Source License

/**
 * Get the item for the given item id//from w  w w.  j av a  2s. c o  m
 * 
 * @param iid The item id
 * @return The item
 */
public Item getItem(Long iid) {
    Session session = StoreHibernateUtil.getSessionFactory().openSession();
    try {
        session.enableFetchProfile("item-with-attributes");

        Item item = (Item) session.get(Item.class, iid);

        return item;
    } finally {
        session.close();
    }
}

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

@Override
public void addCall(Calls call) {
    List<Daily> temp = call.getTasks();
    sessionFactory.getCurrentSession().save(call);
    // if (sessionFactory== null) System.out.println ("null factory");
    if (temp != null && temp.size() != 0) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("calls-with-tasks");

        temp = dailyDAO.getFromProxy(temp);
        for (Daily task : temp) {
            task.getCallsConnectedWithTask().add(call);
            dailyDAO.changeTask(task);//w  ww.  j a va  2  s.  co m
        }
    }

}

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

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

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

@Override
public void addClient(Clients client) {
    List<Documents> temp = client.getDocuments();
    List<Payments> temp2 = client.getPaymentsFromClient();
    sessionFactory.getCurrentSession().save(client);

    //add links to documents
    if (temp != null && temp.size() != 0) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("clients-with-documents");
        temp = documentsDAO.getFromProxy(temp);
        for (Documents doc : temp) {
            doc.getClients().add(client);
            documentsDAO.changeDocument(doc);
        }//from   w  w  w. ja  v a2 s. c  o  m
    }

    if (temp2 != null && temp2.size() != 0) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("clients-with-payments");
        temp2 = paymentsDAO.getFromProxy(temp2);
        for (Payments payment : temp2) {
            payment.setPayerOfPayment(client);
            paymentsDAO.changePayment(payment);
        }
    }

    if (client.getPaymentsToClient() != null) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("clients-with-payments");
        temp2 = paymentsDAO.getFromProxy(client.getPaymentsToClient());
        for (Payments payment : temp2) {
            payment.setReceiverOfPayment(client);
            paymentsDAO.changePayment(payment);
        }
    }

}

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

@Override
public List<Documents> getDocumentsforClient(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-documents");
    Clients client = (Clients) sess.get(Clients.class, id);
    return client.getDocuments();
}

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

@Override
public List<Payments> getPaymentsToClient(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-payments");
    Clients client = (Clients) sess.get(Clients.class, id);
    return client.getPaymentsToClient();
}

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

@Override
public List<Payments> getPaymentsFromClient(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-paymentsFrom");
    Clients client = (Clients) sess.get(Clients.class, id);
    return client.getPaymentsFromClient();
}

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

@Override
public List<Requests> getRequestsFromClient(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-requests");
    Clients client = (Clients) sess.get(Clients.class, id);
    return client.getRequests();
}

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

public List<Contracts> getContractsForClient(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-rolesCont");
    sess.enableFetchProfile("clients-with-contracts");
    Clients client = (Clients) sess.get(Clients.class, id);
    List<Contracts> returnList = new ArrayList<Contracts>();
    List<ContragentsInContract> contrList = client.getParticipantInContracts();
    for (ContragentsInContract con : contrList) {
        returnList.add(con.getContract());
    }//from ww  w. jav a  2s  .c  om
    return returnList;
}