-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Bi-Directional Many-to-Many Schema missing Foregin Key
PostPosted: Thu Oct 14, 2004 4:03 pm 
Newbie

Joined: Fri Oct 31, 2003 3:14 pm
Posts: 12
Location: New York, NY
Hibernate version: 2.1.6

I'm mapping a Bi-directional Many-To-Many and have Hibernate generate the tables via schema update. I'm a bit confused though. Hibernate is only creating one foreign key reference on the table that's used to map the relationship. Here are the mappings slimmed down the important parts:

Code:
   <class
        name="com.foo.user.business.BusinessRole"
        table="BUSINESS_ROLE"
    >

        <id
            name="roleId"
            column="ROLE_ID"
            type="int"
            unsaved-value="0"
        >
            <generator class="native">
            </generator>
        </id>

        <set
            name="users"
            table="BUSINESS_USER_ROLE_MAP"
            lazy="false"
            inverse="true"
            cascade="none"
            sort="unsorted"
        >

              <key
                   column="role_id"
              >
              </key>

              <element
                  column="user_id"
                  type="com.foo.user.business.BusinessUser"
                  not-null="false"
                  unique="false"
              />

        </set>

    </class>


    <class
            name="com.foo.user.business.BusinessUser"
            table="BUSINESS_USER"
        >

            <id
                name="userId"
                column="USER_ID"
                type="int"
                unsaved-value="0"
            >
                <generator class="native">
                </generator>
            </id>

            <set
                name="roles"
                table="BUSINESS_USER_ROLE_MAP"
                lazy="false"
                inverse="false"
                cascade="none"
                sort="unsorted"
            >

                  <key
                      column="user_id"
                  >
                  </key>

                  <element
                      column="role_id"
                      type="com.foo.user.business.BusinessRole"
                      not-null="false"
                      unique="false"
                  />

            </set>

    </class>


It creates good BUSINESS_USER and BUSINESS_ROLE tables, it's the BUSINESS_USER_ROLE_MAP table that isn't what I thought it would be.

BUSINESS_USER_ROLE_MAP only has NOT NULL on USER_ID, but not ROLE_ID. In addtion, USER_ID has a foreign key reference back to BUSINESS_USER, but there is no foreign key reference for ROLE_ID. Why is this? I would think ROLE_ID would get NOT NULL and a foreign key reference as well.

Any ideas?

Thanks,
Patrick


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.