Есть таблица lu (универсальный справочник, который хранит много разных данных, которые используются во многих таблицах), с полями id, tag, code Есть таблица agr с полями id, text, range_id, finance
Таблица с agr связана с lu следующим образом:
- Поле range_id содержит значение поля lu.id, где lu.tag = 7
- Поле finance содержит значение поля lu.code, где lu.tag = 5
Как правильно реализовать связь этих Entity, для правильного добавления записи в таблицу agr
Классы, которые описывают данные таблицы привел ниже
Класс Agr
@Entity
@Table(name = "agr")
public class Agr {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "createdate")
private Date createdate;
@Column(name = "text")
private String text;
@Column(name = "info")
private String info;
@Column(name = "status")
private int status;
@Column(name = "typ")
private String typ;
@Column(name = "code")
private int code;
@Column(name = "bgndate")
private Date bgndate;
@Column(name = "enddate")
private Date enddate;
@Column(name = "finance")
private int finance;
@Column(name = "range_type_id")
private int range_type_id;
@Column(name = "num")
private int num;
public Agr() {
}
public Agr(Date createdate, String text, String info, int status, String typ, int code,
Date bgndate, Date enddate, int finance, int range_type_id, int num) {
this.createdate = createdate;
this.text = text;
this.info = info;
this.status = status;
this.typ = typ;
this.code = code;
this.bgndate = bgndate;
this.enddate = enddate;
this.finance = finance;
this.range_type_id = range_type_id;
this.num = num;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Date getCreatedate() {
return createdate;
}
public void setCreatedate(Date createdate) {
this.createdate = createdate;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getTyp() {
return typ;
}
public void setTyp(String typ) {
this.typ = typ;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public Date getBgndate() {
return bgndate;
}
public void setBgndate(Date bgndate) {
this.bgndate = bgndate;
}
public Date getEnddate() {
return enddate;
}
public void setEnddate(Date enddate) {
this.enddate = enddate;
}
public int getFinance() {
return finance;
}
public void setFinance(int finance) {
this.finance = finance;
}
public int getRange_type_id() {
return range_type_id;
}
public void setRange_type_id(int range_type_id) {
this.range_type_id = range_type_id;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
}
Класс Lu
@Entity
@Table(name = "lu")
public class Lu implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "text")
private String text;
@Column(name = "tag")
private int tag;
@Column(name = "status")
private int status;
@Column(name = "code")
private int code;
public Lu() {
}
public Lu (String text, int tag, int status, int code) {
this.text = text;
this.tag = tag;
this.status = status;
this.code = code;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public int getTag() {
return tag;
}
public void setTag(int tag) {
this.tag = tag;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
}