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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Composite Key
PostPosted: Thu Sep 04, 2008 8:32 am 
Newbie

Joined: Wed Jun 11, 2008 6:39 am
Posts: 1
Hi All,

I am facing problem with compound key implementation. Please solve my problem.

I have 3 tables
Table Columns
Student: studentID, .....
Class : classID,....
Names: studentID,classID,....

Now My problem is In names table I doesnt have any primary key and having only foreign keys.

Now I have to create an composite key using these foreign key values.

It would be helpfull if u provide some code snippet for the same scenerio.

Thanks in Advance


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2008 10:23 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 7:29 am
Posts: 36
Use something like this....

Also notice the way you would have to write the qeries....

Code:
<hibernate-mapping>
    <class name="module.xxxx.model.ViewActiveFilterForUser" table="view_active_filter_for_user" catalog="xxxx">
        <composite-id name="id" class="module.xxx.model.ViewActiveFilterForUserId">
            <key-property name="endUserId" type="java.lang.Long">
                <column name="end_user_id" />
            </key-property>
            <key-property name="id" type="java.lang.Long">
                <column name="id" />
            </key-property>
            <key-property name="description" type="java.lang.String">
                <column name="description" length="50" />
            </key-property>
            <key-property name="key" type="java.lang.String">
                <column name="key" length="50" />
            </key-property>
            <key-property name="index" type="java.lang.Integer">
                <column name="index" />
            </key-property>
            <key-property name="value" type="java.lang.String">
                <column name="value" length="100" />
            </key-property>
        </composite-id>
    </class>       
</hibernate-mapping>

_________________
Shardul
Please Rate.


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