Example usage for javax.persistence EntityManager createQuery

List of usage examples for javax.persistence EntityManager createQuery

Introduction

In this page you can find the example usage for javax.persistence EntityManager createQuery.

Prototype

public Query createQuery(CriteriaDelete deleteQuery);

Source Link

Document

Create an instance of Query for executing a criteria delete query.

Usage

From source file:ec.edu.chyc.manejopersonal.controller.PersonaJpaController.java

public List<Persona> listPersonasConContrato() throws Exception {
    EntityManager em = null;
    try {/* w  ww.j  a v a  2  s  .  c  om*/
        em = getEntityManager();
        Query q = em.createQuery("select p from Persona p where p.contratosCollection is not empty");
        List<Persona> list = q.getResultList();
        return list;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}

From source file:ec.edu.chyc.manejopersonal.controller.PersonaJpaController.java

public List<Persona> listPersonas() throws Exception {
    EntityManager em = null;
    try {//ww  w .j  a  v  a2s . c o m
        em = getEntityManager();
        Query q = em.createQuery(
                "select distinct p from Persona p left join fetch p.personaFirmasCollection where p.activo is not null");
        List<Persona> list = q.getResultList();
        return list;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}

From source file:ec.edu.chyc.manejopersonal.controller.PersonaJpaController.java

public List<Persona> listTodasPersonas() throws Exception {
    EntityManager em = null;
    try {//from w  ww.ja va  2  s.  co m
        em = getEntityManager();
        Query q = em.createQuery(
                "select distinct p from Persona p left join fetch p.personaFirmasCollection where p.id<>1 order by p.activo desc, p.apellidos asc ");
        List<Persona> list = q.getResultList();
        return list;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}

From source file:com.espirit.moddev.examples.uxbridge.newsdrilldown.test.CommandITCase.java

public void printMetaCats() throws Exception {
    System.out.println("\n\n\n");
    EntityManager em = emf.createEntityManager();
    try {/*from w w w.j  a  v  a  2  s. com*/
        EntityTransaction et = em.getTransaction();
        et.begin();
        Query query = em.createQuery(new StringBuilder().append("SELECT x FROM metaCategory x").toString());
        List<NewsMetaCategory> metaList = query.getResultList();
        for (NewsMetaCategory temp : metaList) {
            System.out.println("META: " + temp.getName() + " / " + temp.getLastmodified());
        }
        et.commit();
    } finally {
        em.close();
    }
    System.out.println("\n\n\n");

}

From source file:ec.edu.chyc.manejopersonal.controller.PersonaJpaController.java

public List<Persona> findPersonaConFirma(List<String> firmasAutores) throws Exception {
    EntityManager em = null;
    try {/* ww w  .j  av  a  2s.  c o  m*/
        em = getEntityManager();
        Query q = em.createQuery(
                "select distinct p from Persona p join fetch p.personaFirmasCollection pf where pf.firma.nombre in :firmas order by pf.firma.nombre asc");
        q.setParameter("firmas", firmasAutores);
        List<Persona> list = q.getResultList();
        return list;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}

From source file:ec.edu.chyc.manejopersonal.controller.PersonaJpaController.java

public List<Firma> findFirmas(List<String> firmasAutores) throws Exception {
    EntityManager em = null;
    try {//from   w ww  .  j  a  v  a 2  s.  co  m
        em = getEntityManager();
        Query q = em.createQuery(
                "select distinct f from Firma f left join fetch f.personasFirmaCollection where f.nombre in :firmas order by f.nombre asc");
        q.setParameter("firmas", firmasAutores);
        List<Firma> list = q.getResultList();
        return list;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}

From source file:ec.edu.chyc.manejopersonal.controller.PersonaJpaController.java

public Firma findFirma(Long idFirma) {
    EntityManager em = null;
    try {/*  ww w .  j a  v  a2s  .  com*/
        em = getEntityManager();
        Query q = em.createQuery(
                "select distinct f from Firma f left join fetch f.personasFirmaCollection where f.id=:id");
        q.setParameter("id", idFirma);
        List<Firma> list = q.getResultList();
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}

From source file:ec.edu.chyc.manejopersonal.controller.PersonaJpaController.java

public Persona getPersona(Persona persona) {
    EntityManager em = null;
    try {//from   ww  w  .  ja v  a  2 s  .c om
        em = getEntityManager();
        Query q = em.createQuery("select p from Persona p where p.id=:id");
        q.setParameter("id", persona.getId());
        List<Persona> list = q.getResultList();
        if (list != null && !list.isEmpty()) {
            return list.get(0);
        } else {
            return null;
        }
    } finally {
        if (em != null) {
            em.close();
        }
    }
}

From source file:ec.edu.chyc.manejopersonal.controller.PersonaJpaController.java

public PersonaFirma findPersonaFirma(Long idPersona, Long idFirma) {
    EntityManager em = null;
    try {//from   www .  j  a  v a  2 s.  c om
        em = getEntityManager();
        Query q = em.createQuery(
                "select distinct pf from PersonaFirma pf where pf.persona.id=:idPersona and pf.firma.id=:idFirma");
        q.setParameter("idPersona", idPersona);
        q.setParameter("idFirma", idFirma);
        List<PersonaFirma> list = q.getResultList();
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}

From source file:ec.edu.chyc.manejopersonal.controller.PersonaJpaController.java

public Persona obtenerPersonaVacia() {
    EntityManager em = null;
    try {/*w  ww .j  a  va  2s  . com*/
        em = getEntityManager();
        Query q = em.createQuery(
                "select distinct p from Persona p left join fetch p.personaFirmasCollection where p.id=1");
        List<Persona> list = q.getResultList();
        if (list != null && list.size() > 0) {
            Persona persona = list.get(0);
            Hibernate.initialize(persona.getPersonaFirmasCollection());
            return persona;
        }
        return null;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}