-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Need help with DetachedCriteria
PostPosted: Thu Jul 05, 2007 6:57 am 
Newbie

Joined: Thu Jul 05, 2007 5:51 am
Posts: 2
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.