This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Mapping same POJO to more than one table in Hibernate XML mapping files

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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...


Thank you
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,

 
harsh anajwala
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thank You..
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Harsh/Ran

How to retrieve records for either Table1 or Table2. As similer to saveOrUpdate API, Query.list does not parameter to specify entity-name

Thanks,
Shirish
 
"To do good, you actually have to do something." -- Yvon Chouinard
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!