Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

JOIN syntax for HQL . Need help!

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two tables



I need to join this tables by News.author_id and Users.id.
When I trying to query

I get the following error:
QuerySyntaxException: Path expected for join!

Please help me to resolve this problem.
Thanks in advance for any help.
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the mappings?
See also in the Hibernate documentation, in particular that, to be joinable, the entities need to be associated.
 
Eugene Shaforostov
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Edvins, I already read this reference, but the question remains.

Mapping for table News
News.hbm.xml



Mapping for table Users
Users.hbm.xml
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To use the join syntax, you need a relationship defined (I guess it is a many-to-one in this case) in the mappings. Without it, one can use a query like this:

 
Eugene Shaforostov
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, this query works fine.
But I want to understand how use association mappings.
Mapping files should looks like this?
News.hbm.xml



Users.hbm.xml


If it`s right then what query will return required result?
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not going through the mappings; I would use a query like

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But is it not possible to use something equivalent to a left outer join if the entities don't contain each other as a set?

Edvins Reisons wrote:To use the join syntax, you need a relationship defined (I guess it is a many-to-one in this case) in the mappings. Without it, one can use a query like this:

 
Lisa DeSouza
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But is it not possible to use something equivalent to a left outer join if the entities don't contain each other as a set?

This is my Category:


and this is my Organization:


Similar to the linking in Category I have linking for 2-3 other entities.
I actually needed to retrieve them using an HQL query equivalent to this in MYSQL:


The code you posted is equivalent to a basic join, right? and doesn't retrieve the data I need...

Edvins Reisons wrote:To use the join syntax, you need a relationship defined (I guess it is a many-to-one in this case) in the mappings. Without it, one can use a query like this:

 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Lisa DeSouza wrote:But is it not possible to use something equivalent to a left outer join if the entities don't contain each other as a set?



Well...there is no 'straightforward' way in hibernate to do a "Left Outer Join" when your entities do not have a relationship...

but there are hacks...

Like the following set of SQL demonstrate..



So, if it is hibernate, the above query will work....so you can get the desired result for a join even without using join .. :-)
But such a thing is not recommended, because of the performance impact that it may have if the number of joins on the table are more...and the query becomes complex...etc
 
Lisa DeSouza
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I finally ended up doing.... Thanks!

Rahul Babbar wrote:

Lisa DeSouza wrote:But is it not possible to use something equivalent to a left outer join if the entities don't contain each other as a set?



Well...there is no 'straightforward' way in hibernate to do a "Left Outer Join" when your entities do not have a relationship...

but there are hacks...

Like the following set of SQL demonstrate..



So, if it is hibernate, the above query will work....so you can get the desired result for a join even without using join .. :-)
But such a thing is not recommended, because of the performance impact that it may have if the number of joins on the table are more...and the query becomes complex...etc

 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!