java - HQL to Criteria Conversion Issues -
i have issues converting hql criteria query. part of specification, need return value of criteria query of type criteria, may not changed.
this working hql query:
select sum(m.frequent / case when m.vigilants.size > 1 m.vigilants.size else 1 end) museum m inner join m.vigilants v size(m.vigilants) > 1 , v.forename = 'mike jones' or size(m.vigilants) = 1 , v.forename='mike jones'
and attempt far @ getting criteria query
criteria criteria = session.createcriteria(museum.class, "m"); criteria.createalias("m.vigilants", "v"); criteria.setprojection(projections.distinct(projections.property("m.id"))); criteria.add(restrictions.or(restrictions.sizegt("vigilants", 1), restrictions.eq("v.forename", "mike jones")));
i stuck , have been trying day work, , don't know how can hql converted criteria query!
i have fiddle these things while before correct here first pass start with.
also, whole size > 1 or size == 1
thing boils down size >= 1
implicit if you're doing inner join left out.
criteriabuilder builder = entitymanager.getcriteriabuilder(); criteriaquery<number> query = builder.createquery(long.class); root<museum> root = query.from(museum.class); join<museum, vigilant> vigilantsjoin = root.join("vigilants"); predicate forenameismikejones = builder.equal(vigilantsjoin.get("forename"), "mike joines"); expression<integer> numvigilants= builder.size(root.get("vigilants")); expression<number> freqovernumvigilants = builder.quot(root.get("frequent"), numvigilants); expression<sum> sumoffreqovernumvigilants = builder.sum(freqovernumvigilants); query.select(sumoffreqovernumvigilants).where(forenameismikejones); typedquery<number> typedquery = entitymanager.createquery(query);
Comments
Post a Comment