-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to define composite key in hbm files?
PostPosted: Mon Sep 26, 2005 9:37 am 
Newbie

Joined: Wed Aug 24, 2005 12:07 pm
Posts: 17
Hi Friends,
I have one table called ProjectUser in which one project can b assigned to several users.Now there is a composite key ProjectId+User so how to define it in mapping file throug id.I think in id tag v can define only one column so how to define the composite key in id tag.All suggestions are welcome.
Thanx in advance,
Chirag.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 12:34 pm 
Beginner
Beginner

Joined: Thu Sep 15, 2005 4:16 pm
Posts: 29
Have you looked at the documentation on composite-id? Make sure to also look at the DTD for the element.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 5:18 pm 
Beginner
Beginner

Joined: Mon Sep 22, 2003 5:18 am
Posts: 28
I have the following example of using composite-id element in mapping file:
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="com.real.app.ContentKeyword"
        table="CONTENT_KEYWORDS"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false">

      <composite-id>

         <key-many-to-one
            name="content"
            class="com.real.app.Content"
            column="CONTENT_ID">

         </key-many-to-one>

         <key-many-to-one
            name="keyword"
            class="com.real.app.Keyword"
            column="KEYWORD_ID">

         </key-many-to-one>
         
      </composite-id>

      <property
         name="sortOrder"
         column="SORT_ORDER"
         not-null="false"/>

    </class>
</hibernate-mapping>


Hope this example will help you to start playing with composite-id mapping element in your application


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.