I forgot to mention that when you re-use the foreign key properties of a table in order to access any other tables you have to change your property from
to
Here if you don't remove the first declaration, you are bound to get an error as you cannot use the same property twice. Let me know if you want to know why you get the error you will have to remove the first declaration in your mapping file.
But the advantage of writing the second way, the correct way of mentioning any foreign key relationships in advance, is you can still access your foreign key without causing any performance issues.
An HQL:
will create a sql statement:
Just don't forget all references of your old object which will update/save the particular foreign key property.
You will be replacing
baseTableObj.setForeignKey(someKey)
with
baseTableObj.setParentObj(someParentDao.find(someKey))
change in getters, as I discussed first above, will be simpler though
baseTableObj.getForeignKey()
to
baseTableObj.getParentObj.getPrimaryKey();
I had to do all of this because of improperly generating and designing my mapping file in the first place!
[ May 06, 2008: Message edited by: Rama Krishna ]
[ May 06, 2008: Message edited by: Rama Krishna ]
[ May 06, 2008: Message edited by: Rama Krishna ]