0

I am using hibernate 3.0. I am applying the right outer join. my query is

List<Integer> phaseCount1 = getHibernateTemplate().find("select count(phasesPlan.phaseid.id) as Phase from PhasePlan phasesPlan RIGHT JOIN " +
            "phasesPlan.phaseid as phasedetails and phasesPlan.teamid.teamid=? group by phasedetails.id",team_id);

in this the and condition ( phasesPlan.phaseid as phasedetails **and** phasesPlan.teamid.teamid=? ) is giving unexpected token exception. Any help would be appreciated.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Vaibhav Jain
  • 119
  • 3
  • 16

1 Answers1

0

You will need to replace "and" with "where" :-

find("select count(phasesPlan.phaseid.id) as Phase 
from PhasePlan phasesPlan RIGHT JOIN " +
    "phasesPlan.phaseid as phasedetails **where** phasesPlan.teamid.teamid=? 
group by phasedetails.id",team_id)
Igor
  • 33,276
  • 14
  • 79
  • 112
Vipin Thomas
  • 746
  • 6
  • 7
  • But where is not serving my purpose, when where is applied i am not getting the query result as right join. – Vaibhav Jain Dec 04 '12 at 12:38
  • In this case, we need to specify on which column the join should be :-find("select count(phasesPlan.phaseid.id) as Phase from PhasePlan phasesPlan RIGHT JOIN " + "phasesPlan.phaseid as phasedetails on phasesPlan.teamid.teamid=phasedetails.teamid where phasesPlan.teamid.teamid=? group by phasedetails.id",team_id) – Vipin Thomas Dec 04 '12 at 14:10
  • This is not working.Hibernate doesn not accept 'on' i.e. phasesPlan.phaseid as phasedetails on phasesPlan.teamid.teamid=phasedetails.teamid is giving error – Vaibhav Jain Dec 05 '12 at 06:35
  • Can u try "with" instead of "on" and "and" instead of "where" – Vipin Thomas Dec 05 '12 at 06:57
  • U can also try the options @ http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html#queryhql-joins – Vipin Thomas Dec 05 '12 at 07:01
  • and is not acceptable without where.. This was the original problem – Vaibhav Jain Dec 05 '12 at 08:24