问题
Let's say I have an inheritance graph where the base class extends a mapped superclass:
component name="Entity" mappedSuperClass="true"
{
property name="CreatedOn";
}
component name="Pet" extends="Entity" table="Pet" discriminatorcolumn="pet_type"
{
property name="PetId" fieldtype="id" generator="native";
property name="Name";
}
component name="Dog" extends="Pet" table="Pet" discriminatorvalue="Dog"
{
property name="FavoriteFood";
}
component name="Cat" extends="Pet" table="Pet" discriminatorvalue="Cat"
{
property name="FavoriteSleepingSpot";
}
In this case, I have a Pet
base class with two subclasses, Dog
and Cat
. Pet
also extends Entity
, which provides some auditing properties.
In ColdFusion 9.0.1 and ColdFusion 9.0.1 Hotfix 1, these components are mapped correctly. I verified it by dumping the HBM mappings. However, in ColdFusion 9.0.1 HotFix 2, the mappings are incorrect. For example, the Cat
mapping should be:
<hibernate-mapping>
<subclass discriminator-value="Cat"
entity-name="Cat" extends="cfc:model.Pet"
lazy="true" name="cfc:model.Cat">
<property name="FavoriteSleepingSpot" type="string">
<column name="FAVORITE_SLEEPING_SPOT"/>
</property>
</subclass>
</hibernate-mapping>
But what actually gets generated is this:
<hibernate-mapping>
<subclass discriminator-value="Cat"
entity-name="Cat" extends="cfc:model.Pet"
lazy="true" name="cfc:model.Cat">
<property name="FavoriteSleepingSpot" type="string">
<column name="FAVORITE_SLEEPING_SPOT"/>
</property>
<property name="CreatedOn" type="timestamp">
<column name="CREATED_ON"/>
</property>
</subclass>
</hibernate-mapping>
In other words, the subclass mapping is including the CreatedOn
in the Entity
class when it shouldn't be, and this understandably leads to the following error:
Repeated column in mapping for entity: Cat column: CREATED_ON (should be mapped with insert="false" update="false")
My question is, is something wrong with the way my entities are declared? Or have I stumbled across a bug in Hotfix 2? If so, what would be the fix for it?
The workaround I'm currently using is to dump the HBM files and edit them manually to remove the duplicated property mapping. This is working fine, but I have to repeat this process every time the entities change. Unfortunately, we can't roll back to Hotfix 1 either because we need some of the fixes in Hotfix 2.
来源:https://stackoverflow.com/questions/7972839/wrong-hbm-mappings-when-using-a-mapped-superclass-in-an-inheritance-graph-for-co