I'm planning to map a bill of material structure, where each node needs to be joined to another table based on a column value determined at run time. Rows from this second table appear as a Set in the node POJO. There are many rows in the joined table that belong to each node, but I don't want any that don't satisfy the criterion.
Since it's a bill of material, the top nodes have child nodes (also a Set) which are of the same class the top nodes are, and so on.
Ideally I'd write something like this to get the top-level nodes and get to the associated row via the Set in the node's instance:
Code:
select from Node n outer join fetch Associate a
where a.field = "x"
Unfortunately, as I understand it, I can't have a WHERE clause on the associated table when using "fetch;" but NOT using "fetch" doesn't yield the associated row embedded in the node's POJO.
But I want even more than that! I'd like to iterate over the child Nodes (the second Set mentioned above) Hibernate-style and automatically pull in their associated rows too--using the same criterion with which I chose associated rows at the top of the structure.
Can this be done via a Hibernate mapping? Can it be done the basic POJOs that define the two classes involved? Will I have to define a view in my database (one that joins the tables involved) to pull this off--and if so, how can I map both the view and the original tables to the POJOs?
Thanks for your help.