I'm using Hibernate with a legacy database that has an association table between two other tables. Unfortunately, sometimes either of the things being associated can go into an inactive state without the related association being removed, and there is no state field on the association table itself. When I deal with this table, I do not want to get back rows from the association table where items on either side of the association are in non-active states.
Here is simplistic example of the situation:
Code:
table boys
int b_id
int b_status
varchar b_name
table girls
int g_id
int g_status
varchar g_name
table dating
int d_id
int b_id
int g_id
In this example, boys or girls are active when their status is 0, and inactive for any other status. If either becomes inactive (I dunno, maybe they move to another town!), the dating association is considered inactive, but it is not reflected directly in the association table.
Is there a way to set up the mapping so that when I deal with this association table, rows where either side of the association have a non-active status will automatically not be returned?
In other words, something like <class where="[sql statements]">, but joining against these other tables? Which, I understand, <class where=""> does not support.
Thanks,
Nick