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: Composite Primary key
PostPosted: Mon Jan 30, 2006 12:54 pm 
Newbie

Joined: Mon Jan 30, 2006 12:34 pm
Posts: 2
Hi there,

I have a database model with two tables User and Group. User has 3 attibutes:
username, pass and email. The other table Group also takes username and the name of the group. Due to the existing databse model I cannot make any changes to the tables. However I need to insert multiple users to multiple groups - in a essense a many to many relationship.

The problem I am not allowed to apply a relational table for the 2 primary keys. I was thinking that I could perhaps apply a composite primary key in the group table. Although this will lead lead to redundance, that is not an issue here as I am not allowed to change the database model in anyway.

I use the two classes below to create the composity primary key (memberof + username). Unfortuneately this doesn't work - I would be very grateful for any suggestions.


@Entity(access = AccessType.PROPERTY)
@IdClass(GroupFormPk.class)
public class GroupForm extends ActionForm {

//Integer id;
String username;
String memberof;
List groupList;
String[]groupStrings;



@Id public String getMemberof() {
return memberof;
}
public void setMemberof(String memberof) {
this.memberof = memberof;
}

@Id public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}
@Transient
public List getGroupList() {
return groupList;
}
public void setGroupList(List groupList) {
this.groupList = groupList;
}
@Transient
public String[] getGroupStrings() {
return groupStrings;
}
public void setGroupStrings(String[] groupStrings) {
this.groupStrings = groupStrings;
}

}




@Embeddable
public class GroupFormPk implements Serializable {

String username;
String memberof;

public String getMemberof() {
return memberof;
}
public void setMemberof(String memberof) {
this.memberof = memberof;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 1:12 pm 
Newbie

Joined: Mon Dec 27, 2004 5:38 pm
Posts: 8
try this...
http://opensource2.atlassian.com/projec ... se/XDT-729


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 1:26 pm 
Newbie

Joined: Mon Jan 30, 2006 12:34 pm
Posts: 2
Thanks for the link Luis but I'm using annotations, so unfortuneatly xdoclet information doesn't help me...


Top
 Profile  
 
 Post subject: try
PostPosted: Wed May 31, 2006 9:41 am 
Newbie

Joined: Wed May 31, 2006 8:41 am
Posts: 2
Hi, perhaps these codes can help you


Code:
@Entity
@GenericGenerator(name = "IdSirketKey", strategy = "com.bordronet.util.generator.IdSirketGenerator")
@Table(name="sirket")
public class Sirket implements Serializable{

   /**
    *
    */
   private static final long serialVersionUID = 7519392404377131237L;

   @EmbeddedId
   @GeneratedValue(generator = "IdSirketKey")   
   private SirketPk primaryKeys;

   private String unvan ;
   private String adres ;

......
}


and SirketPK.java


Code:
@Embeddable
public class SirketPk implements Serializable{   
   
   /**
    *
    */
   private static final long serialVersionUID = -7371077337159811295L;

   private int id ;
   private Calendar basTarih ;
   private Calendar sonTarih ;
.....
}


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.