在 ColdFusion 9.0.1 Hotfix 2 的继承图中使用映射的超类时,HBM 映射错误

发布于 2024-12-12 21:37:23 字数 2240 浏览 0 评论 0原文

假设我有一个继承图,其中基类扩展了映射的超类:

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";
}

在本例中,我有一个 Pet 基类,它有两个子类:DogCatPet 还扩展了 Entity,它提供了一些审核属性。

ColdFusion 9.0.1ColdFusion 9.0.1 Hotfix 1 中,这些组件已正确映射。我通过转储 HBM 映射来验证它。但是,在 ColdFusion 9.0.1 HotFix 2 中,映射不正确。例如,Cat 映射应该是:

<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>

但实际生成的是这样的:

<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>

换句话说,子类映射将 CreatedOn 包含在 Entity class ,而它不应该是,这可以理解地导致以下错误:

实体映射中的重复列:Cat 列:CREATED_ON(应使用 insert="false" update="false" 进行映射)

我的问题是,我的实体的声明方式有问题吗?或者我偶然发现了 Hotfix 2 中的错误?如果是这样,解决办法是什么?

我当前使用的解决方法是转储 HBM 文件并手动编辑它们以删除重复的属性映射。这工作正常,但每次实体更改时我都必须重复此过程。不幸的是,我们也无法回滚到 Hotfix 1,因为我们需要 Hotfix 2 中的一些修复。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文