Hibernate mapping class

Can I use the entity-name attribute in a class to set an object and reference it? I want to do this because I want to map multiple tables to the same entity class.

Table 1 and adble 2 have the same layout

 @Entity public class POJO{ @Id @Column(name="column1") private String column1; @Column(name="column2") private String column2; //getters and setters } <hibernate mapping> <class name="package.POJO" entiy-name="EntityTable1" table="table1"> <id>.....</id> <property>....</property> <property>....</property> </class> <class name="package.POJO" entiy-name="EntityTable2" table="table2"> <id>.....</id> <property>....</property> <property>....</property> </class> </hibernate mapping> Session s = SessionFactory.openSession(); List table1List = s.createQuery("FROM EntityTable1").list(); List table1List = s.createQuery("FROM EntityTable2").list(); 

I read in the Hibernate Documentation that this is only at the experimental stage. Has anyone used this method and worked?

+4
source share
1 answer

Yes, you can do it through XML, I have not experienced any problems with this. An example here and here . Here you can find examples here and here .

Note that you cannot do the same with annotations as where XML is more flexible.

+3
source

All Articles