I'm fighting through this same issue. I'm working with a legacy schema and have the following:
Customer (table)
customer_id (int)
Address(table)
address_id (int)
CustomerAddressLink (table)
customer_id (int)
address_id(int)
mailing_address (bool)
shipping_address (bool)
begin_date (date)
end_date (date)
So, I need to actually get at the data in the mapping table. I've tried mapping the Address table with the AddressLink table in a <join> element. However, I'm finding that Hibernate is actually joining the address link table twice in the generated sql, which is killing performance. I assume it's joining once to satisfy the many to many mapping, and again to populate the entity. What's the *best* way to build this mapping such that I'll still be able to use filters to filter by values in address or the link table (I don't want to use criteria because they cause an outer join, I want the addresses to be lazy loaded).
|