I have a mapping of where I have a base table (Tasks) and then an extending table (CRS) but the CRS table actually have date for three different objects. Some of the fields are in common and some are unique. Ignoring the inheritance of the common fields to keep this simple, I have join statements in my three extending classes such as:
Code:
<class name="com.entities.Task" table="tasks"
abstract="true" discriminator-value="0"
<id name="id" type="int" column="TASK_ID">
<generator class="identity" />
</id>
<subclass name="com.entities.SoftwareChangeRequest"
discriminator-value="SCR" extends="com.entities.Task">
<join table="crs">
<key column="TASK_ID" />
.
.
</join>
</subclass>
<subclass name="com.entities.ToolChangeRequest"
discriminator-value="TCR" extends="com.entities.Task">
<join table="crs">
<key column="TASK_ID" />
.
.
</join>
</subclass>
</class>
Each of the three instances join on the CRS table and everything works correctly but when looking at the log I see that a join is performed 3 times on CRS table:
Code:
left outer join crs task0_1_ on task0_.TASK_ID=task0_1_.TASK_ID
left outer join crs task0_2_ on task0_.TASK_ID=task0_2_.TASK_ID
left outer join crs task0_3_ on task0_.TASK_ID=task0_3_.TASK_ID
I see why this is happening but I would think that Hibernate would be able to tell that the joined table is the same in all these instances and to just select all fields for all three concrete classes. Is there anyway around this?