简体   繁体   English

将地图映射到与其在Hibernate中的类相同的表

[英]Mapping a map to the same table as its class in hibernate

I have a rather simple (I think) class that I want to 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>

I got the where="type='access'" trick from mapping multiple sets in one table in hibernate , but the problem is that with the map, the foreign key (A,B,C,X) isn't lining up with the parent table (A,B,C). 我从hibernate的一个表中映射多个集合时得到了where="type='access'"技巧,但是问题在于,使用映射时,外键(A,B,C,X)未与父表(A,B,C)。

Does anyone have any idea how to get this happy? 有谁知道如何使自己开心吗? The PARENT_TABLE would be completely redundant if I have to map the map separately. 如果我必须分别映射地图,则PARENT_TABLE将完全多余。

它不是很漂亮,并且也使Schemaexport变得无用,但是要使其正常工作,您需要指定条件条件以使父级唯一,将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">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM