hibernate - share mapping xml files

122 Views Asked by At

Is there a way to share mapping files for multiple tables.

Every hibernate pojo has a Integer id field which i moved into a superclass. I also have multiple tables which are very similar to each other. So i created superclasses for those either.

Is there a way to include mapping files into each other or share mapping files?

1

There are 1 best solutions below

1
On

The situation you're describing is pretty well handled by hibernate, and you should read the hibernate docs on inheritance mapping (or the equivalent for whatever version you're using) to understand how classes related by inheritance can be mapped.

Reference to other mappings are not by inclusion, but by actual relations between the classes, basically through reference to the inheritance relation between the classes themselves, for example (from the doc):

 <hibernate-mapping>
     <subclass name="DomesticCat" extends="Cat" discriminator-value="D">
          <property name="name" type="string"/>
     </subclass>
 </hibernate-mapping>