将地图映射到与hibernate中的类相同的表

时间:2012-08-09 14:36:49

标签: java hibernate collections map

我想要映射的一个相当简单的(我认为)类:

<class name="parent" table="PARENT_TABLE">
    <composite-id>
        <key-property name = "a" column = "A"/>
        <key-property name = "b" column = "B"/>
        <key-property name = "c" column = "C"/>
    </composite-id>
    <map name = "theMap" table = "PARENT_TABLE" where="type='access'">
        <key foreign-key = "PARENT_TABLE_FK">
            <column name = "A"/>
            <column name = "B"/>
            <column name = "C"/>
        </key>
        <map-key column = "X" type = "double"/>
        <element column = "Y" type = "double" not-null="true"/>
    </map>
</class>

我从mapping multiple sets in one table in hibernate获得了where="type='access'"技巧,但问题是,对于地图,外键(A,B,C,X)没有与父表对齐( A,B,C)。

有谁知道如何让这个快乐?如果我必须单独映射地图,PARENT_TABLE将完全是多余的。

1 个答案:

答案 0 :(得分:0)

它不漂亮并且还使Schemaexport无效但是要使其工作,您需要指定where条件以使父元素唯一,将insert / update设置为false并让映射间接保持父元素。

<class name="parent" table="PARENT_TABLE" where="x = (SELECT x FROM PARENT_TABLE p WHERE p.(a,b,c) = a,b,c LIMIT 1)" insert="false" update="false">