I'm an idiot.
Everything I've tried to explain here is wrong.
Forget all about joining on B. Forget all about my sample SQL. It doesn't describe what I am trying to do.
I can't even come up with a suitable mapping when it's just between two tables.
What I'm REALLY trying to do is this.
I want
Code:
class A {
Set Cs; // a set of C's
Long a_id; // the primary key.
String val1;
String val2;
... // other stuff
}
class C {
Long c_id; // the primary key
String val1;
String val2;
... // other stuff
}
A.val1 and A.val2 together are not unique in A.
C.val1 and C.val2 together are not unique in C.
Nonetheless, I want to populate A.Cs with all C's where A.val1=C.val1
and A.val2=C.val2.
There is no other link between A and C. This relation between A and C is purely incidental.
A and C come from different data sources. The relation is many-to-many.
Each A may have many matching C's, and although I don't think of C's as owning A's in any sense (the association is unidirectional), there may be many A's that match a C based on these two fields.
In other words, I want to populate A.Cs with the results of an ad-hoc query, for each A.
I can't come up with a Hibernate mapping that lets me do that. I don't know what I am missing.