Apologies if this is obvious from the mapping guide, but I can't work it out.
I am in the process of manually creating a mapping for a legacy database and existing Dto object.
The table structure is as follows: a transactional table PERSON has a many-to-one aggregational relationship to COUNTRY, indicating the country in which they live. The foreign key COUNTRY_CODE exists on the PERSON table.
Unfortunately, the PersonDto also contains the country description, i.e. it aggregates an additional column from COUNTRY, which is ignored on insert and update.
The existing Dao, which uses hand-crafted SQL, simply uses a LEFT OUTER JOIN to get this, and then populates the PersonDto from the result set.
How can I map this with Hibernate? IIUC,a <join> is only for extension composed data, i.e. both tables must have the same primary key. It's like I want to specify a many-to-one, but not a class mapping, instead a table mapping where I aggregate a column as a property into the class.
I could use the 'formula="arbitrary SQL expression"' on the property definition, but that will result in multiple queries run, when a left outer join is what is desired.
BTW - I tried to search the forums, but whenever I try to go page 2 onwards of the search results, it tells me no posts matched my query.
|