Multi-table with Criteria

0

Guys I need an example of how to make a multitask in criteria, even though I do not find, I leave a query as an example, I only look for an example not a solution to my query, but the query is that way:

SELECT * FROM
PER_TIPO_REL_SERV TR, PER_DATOS_LISTIN DL WHERE  TR.CTIPO_REL_SERV=DL.TIPO_REL_SERV
    
asked by Geany 30.10.2017 в 11:24
source

1 answer

0

To make a join in JPA Criteria you can see this link link I also send you the example with your query but just make sure you have well mapped the relationships of the tables, I leave the code of how the query could be with criteriaBuilder

CriteriaBuilder cb = em.getCriteriaBuilder();
ArrayList<Predicate> lstPredicates = new ArrayList<>();
CriteriaQuery<PerTipoRelServ> query = cb.createQuery(PerTipoRelServ.class);
Root<PerTipoRelServ> tipo = query.from(PerTipoRelServ.class);
Join<PerTipoRelServ, PerDatosListin> datos = tipo.join("cTipoRelServ");
Predicate pDatos = cb.equal(datos.<Integer>get("tipoRelServ"), cTipoRelServ);
lstPredicates.add(pDatos);
query.where(cb.and(lstPredicates.toArray(new Predicate[lstPredicates.size()])));
List<PerTipoRelServ> lstTipo = em.createQuery(query).getResultList();
    
answered by 30.10.2017 в 16:11