1. i would create the id for the second (StoreAddress) table.
2. then it is quite easy to map the relation (many-to-one) like that:
Code:
<many-to-one name="storeLocator"
class="StoreLocator"
column="storeid"/>
I dont like that the
storid column acts as a primary and foreign key, is there any reason for that?
3. Than you are ready to make association queries following the association from StoreAddress to StoreLocator (to make the association bi-directional, more mapping changes are needed).
Code:
select sa
from StoreAdress as sa
inner join storeLocator as sl
where sl.storeType = 'type_a'
select count(sa)
from StoreAdress as sa
inner join storeLocator as sl
where sl.storeType = 'type_a'
The mapping
many-to-one named 'storedLocator' tells hibernate what tables (classes) it should join using given attribute(s) (column(s)).
You dont have to boher with inner join fetch and such things right now -- it is just an instance fetching strategy, the data returned by hibernate will always be the same.
4. Just an advice: Invest a little time in reading the manual (from the start); the time you spent on it will be well spent. 3 hours of reading and much happier programming! :-)