How to map the table classes have more than one columns for its primarykey in Hibernate?

Discussion in 'Java' started by RC, Apr 10, 2008.

  1. RC

    RC Guest

    I have two existed tables, I am NOT allow to altering those tables
    The 1st table (tableA) has one column for its primary key, the 2nd
    table (tableB) has tow columns for its primary key. I am try to map
    these two tables with Hibernate XML. Here are my XML file.

    Please see ????? in tow places.

    Question 1
    1st ???? is <many-to-many> tag in class TableA, but <many-to-many> tag
    only allows one column. How do I map it for two columns?

    Question 2
    2nd ????? is the <key> tag in class TableB, similar that <key> tag only
    allows one column. How do I map it for two columns?

    Thank Q very much in advance!

    <hibernate-mapping auto-import="false"
    default-lazy="true" default-access="field">

    <class name="tableA" table="TABLEA" entity-name="TableA.class">
    <id name="tableAId" type="string" column="TABLEAID"

    access="field">
    <generator class="native">
    <param name="key">TABLEAID</param>
    </generator>
    </id>
    <property name="column1" type="string" column="COLUMN1" />
    <property name="column2" type="string" column="COLUMN2" />
    .....
    <set name="idsa" table="IDS" inverse="true">
    <key column="TABLEAID" />
    <many-to-many column="????" class="tableB" />
    </set>
    </class>

    <class name="tablesB" table="TABLEB" entity-name="TableB.class">
    <composite-id>
    <!-- this table's primary key has two columns -->
    <key-property name="tableBId1" type="string"
    column="TABLEBID1" />
    <key-property name="tableBId2" type="integer"
    column="TABLEBID2" />
    </composite-id>
    <property name="column1" type="string" column="COLUMN1" />
    <property name="column2" type="string" column="COLUMN2" />
    ....
    <set name="idsb" table="IDS">
    <key column="?????" />
    <many-to-many column="TABLEAID" class="tableA" />
    </set>
    </class>
    </hibernate-mapping>
     
    RC, Apr 10, 2008
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chuck Foster
    Replies:
    4
    Views:
    584
  2. christopher

    map with more than one key type

    christopher, Mar 26, 2007, in forum: C++
    Replies:
    3
    Views:
    441
    David Harmon
    Mar 27, 2007
  3. RC
    Replies:
    0
    Views:
    935
  4. lightning
    Replies:
    0
    Views:
    475
    lightning
    Aug 5, 2008
  5. snehasish
    Replies:
    0
    Views:
    1,764
    snehasish
    Oct 27, 2009
  6. Merciadri Luca
    Replies:
    4
    Views:
    1,062
  7. Wil
    Replies:
    3
    Views:
    172
    Drew Olson
    Jul 19, 2007
  8. Replies:
    3
    Views:
    275
    Gary Herron
    Dec 23, 2013
Loading...