与JoinColumns批注中的referencedColumnsProperty等效的Hibernate映射文件 [英] Hibernate mapping file equivalent of referencedColumnsProperty in JoinColumns annotation

查看:86
本文介绍了与JoinColumns批注中的referencedColumnsProperty等效的Hibernate映射文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人知道与@JoinColumns批注的referencedColumnName属性等效的休眠映射文件,如下所示:

Does anyone know the hibernate mapping file equivalent of the referencedColumnName property of a @JoinColumns annotation, something like this:

@ManyToOne
@JoinColumns ({
    @JoinColumn(name="FIELD_0", referencedColumnName="A", insertable=false, updateable=false),
    @JoinColumn(name="FIELD_1", referencedColumnName="B", insertable=false, updateable=false),
    @JoinColumn(name="FIELD_2", referencedColumnName="C", insertable=false, updateable=false),
    @JoinColumn(name="FIELD_3", referencedColumnName="D", insertable=false, updateable=false)

移动到注释不是一种选择,我们需要使用复合键设置一个外键引用,该复合键的表之间的列名不同.

Moving to annotations is not an option and we need to setup a foreign key reference with a composite key where column names are different between tables.

谢谢.

推荐答案

我一直在研究相同的问题.在解决之前,我已经看到了您的问题,想着我会回到这里为您提供帮助.我正在使用4.2.2.

I've been working on this same problem. I saw your question before I solved it, figured I would come back here and help you. I'm using 4.2.2.

我对名称进行了通用化,但是我想您会明白的. 父"类包含子"对象的集合,这意味着子"表对父"表具有外键约束.

I genericized the names, but I think you will get the point. The "parent" class contains the collection of "child" objects, which means the "child" table has a foreign key constraint to the "parent" table.

请密切注意以下内容: 1.集合键中列的顺序必须与Composite-id中的顺序匹配. 2.手提袋系列的属性非常重要.我下面的东西正在为我工​​作.

Pay close attention to the following: 1. The order of the columns in the collection keys must match the order in the composite-id. 2. The attributes on the bag collection are really important. What I have below is working for me.

<class name="ParentClass" table="parent_table">
    <composite-id name="parentCompositeId" class="ParentCompositeId">
        <key-property name="pkName1" column="pk_name_1" type="integer"/> 
        <key-property name="pkName2" column="pk_name_2" type="string"/>
        <generator class="assigned" />
    </composite-id>

    <property name="name" column="name" type="string" />
    <!-- etc... -->

    <bag name="childObjects" table="child_table" cascade="all" lazy="false" fetch="select">
        <key not-null="true">
            <column name="fk_child_name_1"/>
            <column name="fk_child_name_2"/>
        </key>
        <one-to-many class="ChildClass"/>
    </bag>
</class>

此外,请勿尝试对子"类或其映射配置中的关联进行任何操作.只需映射非FK属性,然后让休眠模式处理FK.

Also, don't try to do anything with the association in either the "child" class or its mapping config. Just map the non-FK properties and let hibernate take care of the FKs.

这篇关于与JoinColumns批注中的referencedColumnsProperty等效的Hibernate映射文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆