How to map 2 identical tables (same properties) to 1 entity
Please help me on this problem.
I have 2 identical tables, one is timetable and开发者_如何学编程 another is timetable_bk. the 2 tables have similar properties or fields. Now I want to map 2 tables to one entity class (alltimetable).
I already tried Inheritance.TABLE_PER_CLASS strategy, but when I query using from AllTimetable. it return nothing.
Please help me. I search many times but did not get the answer yet.
Best Regards.
To map two identical tables to one 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 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 which type of entity you need you call the appropriate session methods as:
_session.Save("Order", myOrder) 
or
_session.Save("OrderHistory", myOrder)
etc. In general entity-name must replace class name in all Hibernate calls.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论