0

我有一个用户类,它具有用户(userid pkey,addr,tel)等属性。现在,我有一个朋友类/表,应该有朋友(invitorid foriegn key references userid,inviteeid foriegn key references userid)和在一起这两个外键将充当主键。我不确定如何在不修改用户表的情况下执行此操作,即我不想将友谊嵌入用户表中。

package hiber;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;

@Entity
@Table(name="users")
public class users {

        @Id
        public int userid=-1;

        private String username;
        private String pw;
        private String fname;
        private String lname;
        private String gender;

        @Column(name="pic")
        @Lob
        private byte[] pic;


        public int getUserid() {
            return userid;
        }
        public void setUserid(int userid) {
            this.userid = userid;
        }
        public String getUsername() {
            return username;
        }
        public void setUsername(String username) {
            this.username = username;
        }
        public String getPw() {
            return pw;
        }
        public void setPw(String pw) {
            this.pw = pw;
        }
        public String getFname() {
            return fname;
        }
        public void setFname(String fname) {
            this.fname = fname;
        }
        public String getLname() {
            return lname;
        }
        public void setLname(String lname) {
            this.lname = lname;
        }
        public String getGender() {
            return gender;
        }
        public void setGender(String gender) {
            this.gender = gender;
        }
        public byte[] getPic() {
            return pic;
        }
        public void setPic(byte[] pic) {
            this.pic = pic;
    }

如何使用两个外键作为复合主键和多对多映射来设计友谊类,因为很多用户可以有很多朋友/

4

0 回答 0