如何将forign密钥构建为主键并与union键相关联

时间:2016-12-02 14:08:51

标签: java hibernate

我有一个用户表,它有一个联合键open_id,现在我想构建一个表 它需要一个与union键相关联的主键。 顺便说一下,我使用mysql5.6,open_id是varchar。 对不起,我不太擅长英语...

CREATE TABLE click ( 
open_id varchar(11) NOT NULL, 
click_count int(11) NOT NULL DEFAULT '0', 
PRIMARY KEY (open_id), 
CONSTRAINT click_ibfk_1 FOREIGN KEY (open_id) REFERENCES user_info (u_openid) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

1 个答案:

答案 0 :(得分:0)

@Entity 公共课圈{

@Id @GeneratedValue
private int id;

@OneToMany(mappedBy = "circle") @JsonIgnore
private List<Enterprise> enterprises;

@OneToMany(mappedBy = "circle")
private List<Authority> authorities;

@Column(nullable = false, length = 50, columnDefinition = "varchar(50) default ''")
private String name;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public List<Authority> getAuthorities() {
    return authorities;
}

public void setAuthorities(List<Authority> authorities) {
    this.authorities = authorities;
}

public List<Enterprise> getEnterprises() {
    return enterprises;
}

public void setEnterprises(List<Enterprise> enterprises) {
    this.enterprises = enterprises;
}

public Circle() {
}

public Circle(int id) {
    this.id = id;
}

public Circle(String name) {
    this.name = name;
}

}

@Entity 公共类企业{

@Id @GeneratedValue
private int id;

@ManyToOne
private Circle circle;

@OneToMany(mappedBy = "enterprise", cascade = CascadeType.ALL)
private List<Creator> creators;

@Column(length = 50, columnDefinition = "varchar(50) default ''") @Size(max = 50)
private String name;

@Column(length = 50, columnDefinition = "varchar(50) default ''") @Size(max = 50)
private String createTime;

@Column(length = 50, columnDefinition = "varchar(50) default ''") @Size(max = 50)
private String category;

@Column(columnDefinition = "text") @Size(max = 500)
private String description;

/**
 * 联系人
 */
@Column(length = 50, columnDefinition = "varchar(50) default ''") @Size(max = 50)
private String contacter;

/**
 * 联系方式
 */
@Column(length = 50, columnDefinition = "varchar(50) default ''") @Size(max = 50)
private String contact;

/**
 * 成员规模
 */
@Column(length = 50, columnDefinition = "varchar(50) default ''") @Size(max = 50)
private String staffSize;

/**
 * 现阶段需求
 */
@Column(columnDefinition = "text")  @Size(max = 500)
private String demand;

/**
 * 公司性质
 */
@Column( columnDefinition = "text")  @Size(max = 500)
private String nature;

/**
 * 业务范围
 */
@Column(length = 50, columnDefinition = "varchar(50) default ''") @Size(max = 50)
private String scope;

@Column(columnDefinition = "text")
private String img1 = "";

@Column(columnDefinition = "text")
private String img2 = "";

@Column(columnDefinition = "text")
private String img3 = "";

@Column(columnDefinition = "text")
private String img4 = "";

@Column(columnDefinition = "text")
private String img5 = "";

public String getImg1() {
    return img1;
}

public void setImg1(String img1) {
    this.img1 = img1;
}

public String getImg2() {
    return img2;
}

public void setImg2(String img2) {
    this.img2 = img2;
}

public String getImg3() {
    return img3;
}

public void setImg3(String img3) {
    this.img3 = img3;
}

public String getImg4() {
    return img4;
}

public void setImg4(String img4) {
    this.img4 = img4;
}

public String getImg5() {
    return img5;
}

public void setImg5(String img5) {
    this.img5 = img5;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getCreateTime() {
    return createTime;
}

public void setCreateTime(String createTime) {
    this.createTime = createTime;
}

public String getCategory() {
    return category;
}

public void setCategory(String category) {
    this.category = category;
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

public String getContacter() {
    return contacter;
}

public void setContacter(String contacter) {
    this.contacter = contacter;
}

public String getContact() {
    return contact;
}

public void setContact(String contact) {
    this.contact = contact;
}

public String getStaffSize() {
    return staffSize;
}

public void setStaffSize(String staffSize) {
    this.staffSize = staffSize;
}

public String getDemand() {
    return demand;
}

public void setDemand(String demand) {
    this.demand = demand;
}

public String getNature() {
    return nature;
}

public void setNature(String nature) {
    this.nature = nature;
}

public String getScope() {
    return scope;
}

public void setScope(String scope) {
    this.scope = scope;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public List<Creator> getCreators() {
    return creators;
}

public void setCreators(List<Creator> creators) {
    this.creators = creators;
}

public Circle getCircle() {
    return circle;
}

public void setCircle(Circle circle) {
    this.circle = circle;
}

}