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.