Hibernate version:
2.1.4
I have several situations where I use the table-per-class-heirarchy mapping. I have found that when I map collections to a specific subtype in this heirarchy it is necessary to provide a where clause to the discriminator column. This is fine for one-to-many mappings, because the discriminator column is on the child table. I have had a problem with many-to-many mappings, however, as I do not know the table alias to use in the where clause, and the discriminator column is not on the join table. I have worked around this problem as well by creating a distinct join table for each type mapping. I am not fully satisfied with this solution, however.
To give a concrete example, I have a stakeholders table to which I map two types of StakeHolders, BoardMember and Employee. I also have a Project object that maps collections of both types.
project.getEmployees() : Collection of Employees;
project.getBoardMembers() : Collection of BoardMembers;
employee.getProjects() : Collection;
boardMember.getProjects() : Collection;
The tables involved would be project, stakeholder (with a disciminator column) and project_stakeholder_lnk
My question has two parts, then
1. Why is specifying the class attribute not sufficient to filter the results to include only the requested subtype?
2. Is it possible to specify a column on the child table (in the example stakeholder) in a where attribute for a many to many mapping?
|