0

Can someone help me in writing equivalent hql for this query

SELECT IFNULL(oea.`organization_name`,'') FROM `consultation_appointment` ca 
JOIN `organization_employee_association` oea ON ca.`consultation_id` = oea.id
JOIN professional_profile pp ON oea.`employee_profile_id` = pp.profile_id

I could able to join the first JOIN like this

select ca.name from ConsultationAppointment ca join ca.consultation oea

Because the ConsultationAppointment class having organization_employee_association variable so it easier to join, difficulty is organization_employee_association not having direct mapping to organization_employee_association class.

Even GORM criteria Query is helpful.

4
  • Well, add this association... Commented Nov 22, 2013 at 7:10
  • @JB Nizet if you don't mind can you make it much more clear Commented Nov 22, 2013 at 7:13
  • You're aware that you need an association between entities in order to create a join between those entities. So add the necessary association. I can't be more precise without knowing any of your entities and tables. Commented Nov 22, 2013 at 8:24
  • Yes, risen because of design issue Commented Nov 22, 2013 at 8:26

1 Answer 1

1

HQL does not allow joining two unassociated entity, you should use cartesian product instead.

String query = "SELECT ca.name FROM consultation_appointment ca JOIN organization_employee_association oea, professional_profile pp WHERE oea.employee_profile_id = pp.profile_id";
List<String> caNames = session.createQuery(query).list();

One another possibility is to use the method createSQLQuery(). It provides more flexibility to execute an arbitrary join.

String query = "SELECT ca.name FROM consultation_appointment ca JOIN organization_employee_association oea ON ca.consultation_id = oea.id JOIN professional_profile pp ON oea.employee_profile_id = pp.profile_id";
List<String> caNames = session.createSQLQuery(query).list();
Sign up to request clarification or add additional context in comments.

2 Comments

but only if there is no possibility we can try this. But there should be some ways in hql we have to dig that
thanks for your effort, but there is error, also we already tried like this, error is on using "on" clause in the query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.