Hi,
What is the alternative in JPA2.0 for the following line?
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
I have a JPA2.0 Criteria, and i need to distinct my root entities.
How can I do that?
Code:
CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
CriteriaQuery<GloCompanyAddress> criteria = builder.createQuery(GloCompanyAddress.class);
Root<GloCompanyAddress> gloCompanyAddressRoot = criteria.from(GloCompanyAddress.class);
//Joins
Join<GloCompanyAddress,GloCompanyAddressPeriod> gloCompanyAddressPeriods = gloCompanyAddressRoot.join(GloCompanyAddress_.gloCompanyAddressPeriods, JoinType.LEFT);
gloCompanyAddressPeriods.alias("gloCompanyAddressPeriod");
Join<GloCompanyAddressPeriod,GloCompanyAddressPeriodLocale> gloCompanyAddressPeriodLocales = gloCompanyAddressPeriods.join(GloCompanyAddressPeriod_.gloCompanyAddressPeriodLocales, JoinType.LEFT);
gloCompanyAddressPeriodLocales.alias("gloCompanyAddressPeriodLocale");
Join<GloCompanyAddressPeriodLocale,GloLocale> gloLocale = gloCompanyAddressPeriodLocales.join(GloCompanyAddressPeriodLocale_.gloLocale, JoinType.LEFT);
gloLocale.alias("gloLocale");
//Fetch
Fetch<GloCompanyAddress,GloCompanyAddressPeriod> gloCompanyAddressPeriodsFetch = gloCompanyAddressRoot.fetch(GloCompanyAddress_.gloCompanyAddressPeriods, JoinType.LEFT);
Fetch<GloCompanyAddressPeriod,GloCity> gloCityFetch = gloCompanyAddressPeriodsFetch.fetch(GloCompanyAddressPeriod_.gloCity, JoinType.LEFT);
gloCityFetch.fetch("gloCountry", JoinType.LEFT);
//restrictions
Predicate restrictions = builder.conjunction();
ParameterExpression<GloCompany> expCompanyId = builder.parameter(GloCompany.class);
restrictions = builder.or(builder.isNull(gloCompanyAddressRoot.get("id")), builder.equal(gloCompanyAddressRoot.get(GloCompanyAddress_.gloCompany), expCompanyId));
criteria.where(restrictions);
//query
criteria.select(gloCompanyAddressRoot);
Query query = getEntityManager().createQuery(criteria);
query.setParameter(expCompanyId,gloCompany);
List rs = query.getResultList();
Thanks in advance,
Pieter