-->
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: Define a Primary key with more than one column
PostPosted: Wed May 21, 2008 5:17 am 
Regular
Regular

Joined: Sun Apr 13, 2008 3:04 am
Posts: 71
Location: Bangalore
Hi,

I have a Groups table, which contains name and users id who has defined this group.

However, the same user can define one and only one group with the same name. This way I need to define a contstraint that combination of name and user_id should be unique i.e multiple entries with same name and user id should not be allowed.

i.e in groups table

name --> user id
family --> 10
family --> 11

should be allowed but not

family --> 10
family --> 10

should not be allowed.

Could any one tell me the way to use the annotations in group class so that such contrants are taken care. I appricate JPA approach if possible else hibernate specific approach is also fine.

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com

_________________
Raja Nagendra Kumar,
C.T.O
http://www.tejasoft.com
TejaSoft - Specialists in Code Audit, Unit Testing and Merciless Re-factoring - Engineering Crisis Turnaround Experts


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 21, 2008 10:17 am 
Newbie

Joined: Wed May 21, 2008 8:33 am
Posts: 5
Hi,
Is name and group form the primary key of the entity. If so why not define a composite key for the table.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 21, 2008 1:32 pm 
Regular
Regular

Joined: Sun Apr 13, 2008 3:04 am
Posts: 71
Location: Bangalore
Nope application level key defination may be to heavy for this requirment.. I am hoping there would be a simpler way..

I have come across annotations like..

@Table(name = "TBL_GROUPS",
uniqueConstraints = {@UniqueConstraint(columnNames = {"name", "fk_user"})})


Regards,
Nagendra

_________________
Raja Nagendra Kumar,
C.T.O
http://www.tejasoft.com
TejaSoft - Specialists in Code Audit, Unit Testing and Merciless Re-factoring - Engineering Crisis Turnaround Experts


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.