hbnUtil.closeSession(); %> Test completed </body> </html>
The records did get saved for TernaryA, TernaryB, and TernaryC. But nothing was saved in table TernaryAll, did I miss something?
Also what will be a better way to handle ternary relationship in Hibernate? I actually have a table that has a composite key containing four columns (three as foreign keys, and the last one is some assigned value).
The only thing that looks suspect to me is giving the A, B and C objects the same Set of TernaryAlls. It probably doesn't make a difference in this case since you're just creating and saving the objects, but it will cause issues later if you have continue adding more objects or use a second-level cache. For example, if you added a new TernaryAll that linked to TernaryA and two new TernaryB and TernaryC instances, the original TernaryB and TernaryC would get the new TernaryAll added to their Set since it's the same Set that TernaryA has.
I only know that the Hibernate developers will tell you again and again not to use composite IDs, and I can say from a database and general ORM point-of-view that they are a major PITA. If you can create a surrogate key for that table, it will be much easier.
Okay, reading the Hibernate mapping docs for composite-id I notice that it says there are two types of columns: key-property and key-many-to-one. Have you tried using the latter as it seems to be what you'd want?
As for more information on ternary (and more) associations, the Hibernate docs briefly mention ternary associations.