Answer the question
In order to leave comments, you need to log in
How to correctly define Entity if part of the data is stored in the properties table?
There is an entity, part of whose data is stored in a regular table, and the other in a property table (PK - Attribute_Name - Attribute_Value). The set of properties may differ for different types of this entity.
@Entity
@Table(name = "PEOPLE")
public class People {
@Id
private int codePeople;
@Column(name = "FAM")
private String fam;
@Column(name = "IM")
private String im;
@Column(name = "OTCH")
private String otch;
...
}
// Свойства
@Table(name = "PEOPLE_ATTRIBUTE")
@Column(name = "Code_People")
@Column(name = "Code_Attr")
@Column(name = "Value_Attr")
// Cобственно: В зависимости от региона адрес человека хранится в разных видах
// 1 - Полное название (Регион, Город, Улица, Дом...)
// 2 - Региональные Код региона Код улицы Дом (то есть несколько строк в таблице свойств)
// 3 - Код КЛАДР
// 4 - Код ФИАС
// И таких различных атрибутов около сотни
Answer the question
In order to leave comments, you need to log in
As one of the options - you can do it with the @OneToMany annotation. Create a separate entity on the PEOPLE_ATTRIBUTE table, for example
@Entity
@Table(name = "PEOPLE_ATTRIBUTE")
public class PeopleAttribute {
private int peopleCode;
private int attributeCode;
private String attributeValue;
...
}
@Entity
@Table(name = "PEOPLE")
public class People {
...
private Set<PeopleAttribute> attributes;
@OneToMany(mappedBy = "attribute")
public Set<PeopleAttribute> getAttributes() {
return this.attributes;
}
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question