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

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


Hi,

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(
schema,
catalog,
getClassTableName( joinedSubclass, node, schema, catalog, null, mappings ),
getSubselect( node ),
false

For union-subclass, the mapping gets added with

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

mappings.addTable doesnt throw exception if the table mapping already
exists.

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?

Thanks,
Unmesh


More information about the hibernate-dev mailing list