Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4050062
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:01:24+00:00 2026-05-20T14:01:24+00:00

I have table1 and table2 that have the same schema… and I want to

  • 0

I have table1 and table2 that have the same schema… and I want to have only one entity rather than two ( since the fields will be the same).
How would I achieve that in hibernate with XML mapping.
So my goal is when I m querying in the DAO, how would it know which table to pull from if both tables are mapped to the same entity.

I m trying to Not create a parent class and then two subclasses.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:01:25+00:00Added an answer on May 20, 2026 at 2:01 pm

    Sorry for the late answer. i have answered this question several times on stackoverflow.


    To map two identical tables onto one entity class, you need to use the entity-name property of Hibernate or NHibernate.

    Documentation is here:
    http://docs.jboss.org/hibernate/core/3.2/reference/en/html/mapping.html#mapping-entityname

    For example, to map a single class Order to Order and OrderHistory tables, you create a mapping file that maps the order class to the two tables using new entity-names (Order and OrderHistory) like this:

    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
       <class name="DomainModel.Order, DomainModel"
       table="Orders" entity-name="Order">`  
         <id name="_id" access="field" column="OrderId">
             <generator class="assigned"/>
         </id>
        <property name= ...>
    </class>
    <class name="DomainModel.Order, DomainModel"
     table="OrderHistories" entity-name="OrderHistory">
         <id name="_id" access="field" column="OrderId">
            <generator class="assigned"/>
         </id>
        <property name= ...>
    </class>
    </hibernate-mapping>
    

    Then depending on the type of entity you need, you simply call the appropriate Session methods as:

    _session.Save("Order", myOrder) 
    

    or

    _session.Save("OrderHistory", myOrder)
    

    Simple, isn’t ?

    In general entity-name must replace class name in all Hibernate calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables (TABLE1, TABLE2 - unique i know) that has a 1-to-many
I have 2 tables with the same schema, one is just a table that
I have two tables both have same schema, one will have previous day records
I have two tables, A and B, that have the same structure (about 30+
I have two tables with the exact same schema in SQL Server 2008 Standard
I have a two tables, one that contains basic resource info, with columns and
I've got a bunch of strongly typed DataSet that each have two tables. One
Let's say I have 50 databases that all have same schema and all have
I have three databases with exactly the same schema (SAP Business One databases). In
I'm seeing basically the same issue described here I have a table that starts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.