【发布时间】:2016-07-04 08:46:34
【问题描述】:
我想将3列地址(国家、州、城市)映射到配置表id列。
我的表结构如下:
地址模型/表
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@Entity
@Table(name = "addresses")
public class Address {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private Configuration configuration;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "id")
private int country;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "id")
private int state;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "id")
private int city;
private int zipCode;
@Column(name = "created_at")
private Date createdAt;
@Column(name = "created_by")
private String createdBy;
@Column(name = "updated_at")
private Date updatedAt;
@Column(name = "updated_by")
private String updatedBy;
private String status;
private String deleteFlag;
}
配置模型/表
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
@Entity
@Table(name = "configurations")
public class Configuration {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@NotNull
private String configurationName;
@NotNull
private String configurationType;
@NotNull
private String ConfigurationDescription;
@Column(name = "parent_id")
private long parentId;
}
在这里,我无法映射配置与地址和配置之间的关系。
请朋友们在这方面帮助我。
更新
**Configurations Table record**
id configname configtype configdescription parentid created_at updated_at Status deleteflag
1 India Country This is a country 0 12-05-2016 Null Active Null
2 Delhi State This is a State 1 12-05-2016 Null Active Null
3 New Delhi City This is a city 2 12-05-2016 Null Active Null
----------
**Address Table record**
id Country State City zipcode created_at updated_at status deleteflag
1 1 2 3 110034 12-05-2016 Null Active Null
【问题讨论】:
-
你想要地址和配置之间的关联吗????
-
我已经更新了我想要的,请看。
-
您想将您的地址类中的州城市和国家成员映射到配置中的相应行..我是rt吗??
-
是的。这就是我想要的。我也在寻找诸如加入子类或每个类的表等替代方案。
-
请在我的回答中查看下面的更新
标签: java mysql spring hibernate jpa