Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reg how to write Inner join in hibernate

 
Barry Van
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

i am using this query but getting error.

StringBuffer selectClause = new StringBuffer(
" select jswe.employerName, jswe.employerAddress, jswe.startFrom, jswe.endTo, jswe.visible, jswe.sortOrder, ");
selectClause.append(" jswel.businessSector, jswel.occupationTitle, jswel.mainActivities ");
StringBuffer fromClause = new StringBuffer("from CvoJsWorkExperience as jswe ");
fromClause.append(" left join jswe.CvoJsWorkExperienceLingual as jswel ");
StringBuffer onClause = new StringBuffer(" on jswe.id=jswel.cvoJsWorkExperience ");
StringBuffer whereClause = new StringBuffer(" where cvoJobseeker= ");
whereClause.append(id);

please any one modify the query which is work properly.

error messege :
ERROR com.eurodyn.cvo.facade.FacadeException: org.hibernate.QueryException: outer or full join must be followed by path expression [select jswe.employerName, jswe.employerAddress, jswe.startFrom, jswe.endTo, jswe.visible, jswe.sortOrder, jswel.businessSector, jswel.occupationTitle, jswel.mainActivities from com.eurodyn.euresportal.pojos.CvoJsWorkExperience as jswe inner join fetch CvoJsWorkExperienceLingual as jswel on jswe.id=jswel.cvoJsWorkExperience where cvoJobseeker= 477841]
org.hibernate.QueryException: outer or full join must be followed by path expression [select jswe.employerName, jswe.employerAddress, jswe.startFrom, jswe.endTo, jswe.visible, jswe.sortOrder, jswel.businessSector, jswel.occupationTitle, jswel.mainActivities from com.eurodyn.euresportal.pojos.CvoJsWorkExperience as jswe inner join fetch CvoJsWorkExperienceLingual as jswel on jswe.id=jswel.cvoJsWorkExperience where cvoJobseeker= 477841]
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There should not be any "on clause" in your HQL.
This is because Hibernate does a Join based on the associations between the tables.
So, if you have two Entities A and B, with A having a relationship with B, you can write your HQL like
"Select ...... from A Left Join B where...."
There should not be any on clause because Hibernate will automatically use the entity mappings to append the appropriate while making HQLs.
However, if there is no relationship between the entities A and B, you cannot use the Join.
but as a workaround, you might want to put the condition in the where clause and try to get the records.
Ex: If both you wanted to do an inner join on tables A and B through cols col1 and col2 in the tables respectively,
you might do something like,
Select ......from A, B where A.col1 = B.col2 and .....<other conditions..>

So, in your case remove the "on condition ", instead put the condition as a where condition.

Hope it helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic