I have back up table kind of thing in my database. i.e after some period some table are created newly(due to huge data present in the existing table) which is same as existing table. This new table will be used to insert new data but old table can be useful for select purpose.
So i would like to map single POJO to both table. These tables are created dynamically after particular period so at the time of generation of new table ,this table should be mapped to same POJO to which existing table was mapped...
So can i mention two tables in class tag for the mapping?
Or any other way to do this...
It is possible to map a single POJO class to two tables using Hibernate. First create your object and its related HBM (xml) file. Then copy the HBM file and rename it to something similar. In the first HBM you will have something like the following. Please note the use of entity-name element.
In the second HBM you will have something like:
Then in your data layer you will have code something like:
Of course the above requires that your table actually exist, thus the dynamic creation of the table will be a problem.
Good luck friend,
Joined: Oct 13, 2009
Thank you Ran for the reply...I got it..But do i need to make two different XML for both mapping purpose.
And if I merge both XML in to one XML File then should I simply copy mapping(which is same) of both files one after another?that will create redundancy..so ideally that should not be the case..
Can you explain me How merged XML will look like?