How to make a Criteria Join for this query

0

By searching a little I realized that there are some ways to make a Join using criteria.

One of them is using an alias and one using a root.

How to do the query below in Criteria using the 2 forms and which of the two would be the best (best in relation to performance)?

Select c.id from entidade c inner join entidade2 e where c.id=e.idC; 

Does anyone know of a site with beautiful documentation regarding Criteria and Joins?

I know a way to do but returns the entire entity and it's not quite the way I want it because I want only the entity's id.

   Criteria c = session.createCriteria(Entidade.class, "C");
     c.createAlias("C.entidades1", "e");
     c.add(Restrictions.eq("c.id", "e.idC"));
     c.list();
    
asked by anonymous 23.03.2018 / 11:55

1 answer

1

If the criteria that you presented are returning the entity you want, just do the setProjection:

Criteria c = session.createCriteria(Entidade.class, "C");
     c.createAlias("C.entidades1", "e");
     c.add(Restrictions.eq("c.id", "e.idC"));
     c.setProjection(Projections.property("c.id"));
     c.list();

For documentation, this site is very good: link

    
09.08.2018 / 23:00