aspose file tools*
The moose likes Object Relational Mapping and the fly likes Reg  how to write Inner join  in hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Reg  how to write Inner join  in hibernate" Watch "Reg  how to write Inner join  in hibernate" New topic
Author

Reg how to write Inner join in hibernate

Barry Van
Greenhorn

Joined: Oct 23, 2008
Posts: 22
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

Joined: Jun 28, 2008
Posts: 210
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


Rahul Babbar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reg how to write Inner join in hibernate