0

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

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.

Community
  • 1
  • 1
pennstatephil
  • 1,593
  • 3
  • 22
  • 43
  • what does *isn't lining up* mean? Also is A,B,C not unique but duplicated for each X,Y combination? – Firo Aug 14 '12 at 06:18
  • as in, it wants the keys of the parent to match the keys of the child, which cannot be since it's a map and has the additional key column of 'X'. You are correct that ABC is duplicated for each child row. What I am trying to do is prevent having two tables with identical data for the ABC columns. – pennstatephil Aug 14 '12 at 14:56

1 Answers1

0

it is not pretty and also renders Schemaexport useless but to get it work you need to specify a where condition to make the parent unique, set insert/update to false and let the map persist the parent indirectly.

<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">
Firo
  • 30,626
  • 4
  • 55
  • 94