Hello all, I have a database with 3 tables. The main table is Contract, and it is joined with pairs of keys from two tables: Languages and Regions. each pair is unique, but it is possible that one contract will have the following pair ids: { (1,1), (1,2), (2,1), (2,2) } Today, the three tables are linked via a connecting entity called ContractLanguages. It contains a sequence id, and triplets of ids from the three tables. However, in large enough contracts this causes a serious performance issue, as the hibernate environment creates a staggering amount of objects. Therefore, we would like to remove this connecting entity, so that Contract will hold some collection of these pairs.
Our proposed solution: create an @embeddable class containing the Language and Region id's, and store them in the Contract entity. The idea behind this is that there is a relatively small number of languages and regions. We are assuming that hibernate manages a list of such pairs and does not create duplicates, therefore substantially reducing the amount of objects created.
However, we have the following questions: 1. Will this solution work? Will hibernate know to create the correct object? 2. Assuming the solution works (the link is created correctly), will hibernate optimize the object creation to stop creating duplicate objects? 3. If this solution does not work, how do we solve the problem mentioned above without a connecting entity?
|