-->
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.  [ 4 posts ] 
Author Message
 Post subject: Don't want PK to include composite-element extra columns
PostPosted: Mon Nov 15, 2004 4:35 pm 
Newbie

Joined: Tue Jul 06, 2004 10:57 pm
Posts: 4
What if I don't want the primary key of the many-to-many association table created by the composite-element with many-to-one technique to include the extra columns? I only want the two foreign keys to make up the composite primary key, and not the extra column information. I actually have a use-case for this, as I am mapping to a legacy database.

Take the example on page 229 of HiA to illustrate (the section with the title Using a collection of components for a many-to-many association). I want the primary key of the CATEGORY_ITEMS table to only be the composite of CATEGORY_ID and ITEM_ID. I still want the extra columns, like USERNAME and DATE_ADDED, I just don't want them to be a part of the composite primary key. How do I do this?

Warmest regards, Matt


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 15, 2004 5:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
A <key> can have <columns> inside it to define multiple keys - as per the DTD and documentation ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 17, 2004 9:22 pm 
Newbie

Joined: Tue Jul 06, 2004 10:57 pm
Posts: 4
I don't think your answer applies in my case, as the <composite-element> is automatically creating keys. With regards to the example on page 229 of HiA, could you show us how you would do what you suggest? Here is the code:

Code:
<set name="items" lazy="true" table="CATEGORY_ITEMS">
      <key column="CATEGORY_ID"/>
      <composite-element class="CategorizedItem">

        <parent name="category"/>
        <many-to-one name="item" class="Item" column="ITEM_ID" not-null="true"/>
        <property name="username" column="USERNAME" not-null="true"/>
        <property name="dateAdded" column="DATE_ADDED" not-null="true"/>
      </composite-element>
</set>


This code will make a comosite primary key out of all four columns: CATEGORY_ID, ITEM_ID, USERNAME and DATE_ADDED. However, I only want the comosite primary key to be made up of the two columns CATEGORY_ID and ITEM_ID. I still want the other two columns to be in the table and not-null, but I don't want them to be a part of the composite primary key. How do I do this?

Warmest regards, Matt


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 5:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
If you want additional properties that is not part of the key - then why don't you just use a stanard <one-to-many> association ?

Also look at <idbag> (which give you support for additonal props - but requires a surrogate key)

_________________
Max
Don't forget to rate


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

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.