(Parenthetical rant:) I'm a Hibernate beginner getting slightly frustrated by the overhead of a simple join that I could write in 15 seconds in SQL. (End rant)
The situation is thus: I have 2 tables that both contain the same composite primary key - let's call the columns in both tables 'ID' and 'Version'. I need data about a particular ID/Version from both tables, so
select a.xxx, b.yyy
from tableA a, tableB b
where a.ID = b.ID
and a.Version = b.Version
and .....
Bad table design, but not in my hands.
In Hibernate, my online research suggests creating a separate composite key class to be shared by the tables, with an A object containing a B object, and a one-to-one mapping between them in A's hbm file.
In my project, all my Hibernate data objects are generated with hbm files and located in the same place. So I'd like to know if I can create this composite key object also using an hbm file and store it with its brethren. The issue is, it doesn't map to any table in particular (or, you could say it maps to 2 tables). I'm trying to determine if it's possible to create this composite key class with an hbm file, and also if it's advisable or not to do so. Am I going about this the wrong way?
Thanks in advance.