(1) HQL/JPQL: select p, a from Reunion p, meeting a where p.number=a.number and p.state='active'
(2) QBC Unfortunately, QBC does not support cross join(or multiple "from" keywords), it only supports join by asscoaition Criteria criteria = session.createCriteria(Eunion.class); criteria.createAlias("meeting", m); //Class "Reunion" must has a one-to-one property "meeting", this statment contains "this.number == m.number" implicitly, so need not to do this in where criteria.addRestriction(Restrictions.eq("this.state", 'active')); criteria.setProjection(Projections.list("this", "m")); //Not very sure, because haven't use QBC for near ten years
(3) JPACriteria(recommand, JPA API, not Hibernate API, typed safe, but need maven plugin to generate source code at compilation-time)
// If any error, report error at compliation-time, not runtime. So cool!!! CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Object[]> cq = cb.createCriteria(Object[].class); Root<Reunion> p= cq.from(Reunion.class); Root<Metting> a = cq.from(Meeting.class); cq .where( cb.equal(p.get(Reunion_.number), a.get(Meeting_.number)) //Reunion_ and Meeting_ are two new classes generated by maven plugin cb.equal(p.get(Reunion_.state), "active") ) .multiselect(p, a); return entityManager.createQuery(cq).getResultList();
_____________________________________________________________
By the way, help me to let more Hibernate friends know: https://github.com/babyfish-ct/babyfish
|