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
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-nameproperty 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(OrderandOrderHistory) like this:Then depending on the type of entity you need, you simply call the appropriate Session methods as:
or
Simple, isn’t ?
In general
entity-namemust replace class name in all Hibernate calls.