Hi I am trying to make this SQL in hibernate but I cant make the DetachedCriteria as it should be, can anyone help me please :)
SELECT EXTRACT (YEAR FROM createdate)
|| '-'
|| EXTRACT (MONTH FROM createdate)
|| '-'
|| EXTRACT (DAY FROM createdate) AS y0_,
this_.authorityfoaid AS y1_, this_.serviceid AS y2_,
this_.supplierid AS y3_, this_.serviceentityid AS y4_,
this_.calledfrom AS y5_, authorityf1_.foa_text AS y6_,
service2_.NAME AS y7_, supplier3_.NAME AS y8_,
COUNT (this_.calledfrom) AS y9_
FROM stat this_,
serviceentity serviceent5_,
entitytype entitytype6_,
service service2_,
supplier supplier3_,
supplier parent4_,
foa_link authorityf1_
WHERE this_.serviceentityid = serviceent5_.ID
AND serviceent5_.entitytype = entitytype6_.ID
AND this_.serviceid = service2_.ID
AND this_.supplierid = supplier3_.ID
AND supplier3_.PARENT = parent4_.ID(+)
AND this_.authorityfoaid = authorityf1_.foa_id(+)
AND EXISTS (
SELECT this0__.serviceentity AS y0_
FROM serviceauthorityacl this0__, authority aut
WHERE this0__.authority = aut.id
AND this0__.serviceentity = serviceent5_.id
AND aut.AUTHORITYLEVEL=3)
GROUP BY EXTRACT (YEAR FROM createdate)
|| '-'
|| EXTRACT (MONTH FROM createdate)
|| '-'
|| EXTRACT (DAY FROM createdate),
this_.authorityfoaid,
this_.serviceid,
this_.supplierid,
this_.serviceentityid,
this_.calledfrom,
authorityf1_.foa_text,
service2_.NAME,
supplier3_.NAME
ORDER BY y0_ ASC,
authorityf1_.foa_text ASC,
service2_.NAME ASC,
supplier3_.NAME ASC
My code looks like this:
Criteria crit = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Stat.class);
crit.createCriteria("authorityFOA", "authorityFOA", CriteriaSpecification.LEFT_JOIN);
crit.createCriteria("service", "service", CriteriaSpecification.INNER_JOIN);
crit.createCriteria("supplier", "supplier", CriteriaSpecification.INNER_JOIN).createCriteria("parent", "parent", CriteriaSpecification.LEFT_JOIN);
Criteria entityCrit = crit.createCriteria("serviceEntity", "serviceEntity", CriteriaSpecification.INNER_JOIN);
entityCrit.createCriteria("entityType", "entityType", CriteriaSpecification.INNER_JOIN);
crit.setProjection(Projections.projectionList()
.add(Projections.groupProperty("niceDate").as("niceDate"))
.add(Projections.groupProperty("authorityFOA").as("authorityFOA"))
.add(Projections.groupProperty("service").as("service"))
.add(Projections.groupProperty("supplier").as("supplier"))
.add(Projections.groupProperty("serviceEntity").as("serviceEntity"))
.add(Projections.groupProperty("calledFrom").as("calledFrom"))
.add(Projections.groupProperty("authorityFOA.foaText"))
.add(Projections.groupProperty("service.name"))
.add(Projections.groupProperty("supplier.name"))
.add(Projections.count("calledFrom").as("clicks")));
crit.addOrder(Order.asc("niceDate"));
crit.addOrder(Order.asc("authorityFOA.foaText"));
crit.addOrder(Order.asc("service.name"));
crit.addOrder(Order.asc("supplier.name"));
DetachedCriteria acl = DetachedCriteria.forClass(ServiceAuthorityACL.class, "acl");
acl.setProjection(Property.forName("serviceEntity"));
acl.createAlias("authority", "authority");
acl.createAlias("serviceEntity", "serviceEntity");
acl.add(Property.forName("acl.authority").eqProperty("authority.id"));
acl.add(Property.forName("acl.serviceEntity").eqProperty("serviceEntity.id"));
Criterion autLevelCrit = Subqueries.exists(acl);
crit.add(autLevelCrit);
And it is creating this output, my problem is highlighted in red:
/* Formatted on 2007/07/05 12:47 (Formatter Plus v4.8.7) */
SELECT EXTRACT (YEAR FROM createdate)
|| '-'
|| EXTRACT (MONTH FROM createdate)
|| '-'
|| EXTRACT (DAY FROM createdate) AS y0_,
this_.authorityfoaid AS y1_, this_.serviceid AS y2_,
this_.supplierid AS y3_, this_.serviceentityid AS y4_,
this_.calledfrom AS y5_, authorityf1_.foa_text AS y6_,
service2_.NAME AS y7_, supplier3_.NAME AS y8_,
COUNT (this_.calledfrom) AS y9_
FROM stat this_,
serviceentity serviceent5_,
entitytype entitytype6_,
service service2_,
supplier supplier3_,
supplier parent4_,
foa_link authorityf1_
WHERE this_.serviceentityid = serviceent5_.ID
AND serviceent5_.entitytype = entitytype6_.ID
AND this_.serviceid = service2_.ID
AND this_.supplierid = supplier3_.ID
AND supplier3_.PARENT = parent4_.ID(+)
AND this_.authorityfoaid = authorityf1_.foa_id(+)
AND EXISTS ( SELECT this0__.serviceentity AS y0_ FROM serviceauthorityacl this0__ WHERE this0__.authority = authority1_.ID AND this0__.serviceentity = serviceent2_.ID)
GROUP BY EXTRACT (YEAR FROM createdate)
|| '-'
|| EXTRACT (MONTH FROM createdate)
|| '-'
|| EXTRACT (DAY FROM createdate),
this_.authorityfoaid,
this_.serviceid,
this_.supplierid,
this_.serviceentityid,
this_.calledfrom,
authorityf1_.foa_text,
service2_.NAME,
supplier3_.NAME
ORDER BY y0_ ASC,
authorityf1_.foa_text ASC,
service2_.NAME ASC,
supplier3_.NAME ASC
/Thanks
|