[hibernate-dev] Multiple joined-subclass mappings to same table

Unmesh Joshi unmeshjoshi at gmail.com
Tue Feb 10 19:35:46 EST 2015


I am bit puzzled with this. I am looking at a codebase, where there are
multiple joined-subclass mappings (in separate hbm.xml files) which map to
same table. For union-subclass, we correctly get exception for duplicate
mapping. But for joined-subclass it allows multiple mappings to same table.
In the hibernate source code, I see that for Joined subclass, the table
mapping is added with following method call.

Table mytable = mappings.addTable(
getClassTableName( joinedSubclass, node, schema, catalog, null, mappings ),
getSubselect( node ),

For union-subclass, the mapping gets added with

Table mytable = mappings.addDenormalizedTable(
getClassTableName(unionSubclass, node, schema, catalog,
denormalizedSuperTable, mappings ),
unionSubclass.isAbstract() != null && unionSubclass.isAbstract(),
getSubselect( node ),

mappings.addTable doesnt throw exception if the table mapping already

Is the behaviour for joined subclass by design? Because I see this fact
being used in some projects, where to extend an already created
joined-subclass, a new hibernate-config file is added with joined-subclass
definition duplicated, with additional attributes (and columns) added to
existing table. So essentially, you have two joined-subclass definitions,
mapping two separate entities to same table.
This does look like using some loop hole in the code?


More information about the hibernate-dev mailing list