Reputation: 2678
I'm terribly sorry to bother Stack Overflow with yet another question on those hibernate queries, but it's been four hours or so I've tried to fix this issue, with no success so far.
The problem is as follow. I've got a model that deals with "Quotes", "Sources" and "Positions". A Quote is a quote from a book, a play, a thesis, etc. - this diversity is what "Sources" objects are. And the exact place where the quote is in the Source is the Position. So, for instance, "blablablabla" (quote) is on "page 12 on chapter 5" (Position) of "The Art Of Programming" (Source).
Now, I want to get every "Positions" already registered for a "Source". But there is no direct mapping between those two, and I'd like to avoid making this connection (though I'm beginning to believe there is no other solutions). On the other hand, Quote objects have a Source and a Position.
This is an excerpt from the quote class :
public class Quote
{
@ManyToOne(cascade=CascadeType.ALL)
Position position;
@ManyToOne(cascade=CascadeType.ALL)
Source source;
// ... other stuff
}
At first, I simply got some "no path for join" exceptions, so I read everything I could find on Stack Overflow. If I understand correctly, my query should look something like :
currentSession.createQuery("from Position
inner join Quote quote, Source source where quote.source = :idSource");
But even like that I got this exception :
Unable to resolve path [quote.source], unexpected token [quote]
Have I made a mistake somewhere or am I asking too much of Hibernate ? Thank you in advance for your help.
Upvotes: 1
Views: 481
Reputation: 100806
The query you're looking for is:
select q.position
from Quote q
where q.source = :source
Note that you should be passing the actual Source
entity as parameter here; if you only want to pass its id the last line should instead read where q.source.id = :idSource
(assuming your identifier property is id
).
Upvotes: 1