I have a following database structure:
Code:
BASE_OBJECT ATTRIBUTE_VALUE ATTRIBUTE
----------------- --------------------- ---------------
PK BASE_OBJECT_ID<--\ PK ATTRIBUTE_VALUE_ID /--->PK ATTRIBUTE_ID
\------FK BASE_OBJECT_ID / NAME
FK ATTRIBUTE_ID------------/
VALUE
Is it possible for BaseObject to get his attribute values through a map by ATTRIBUTE.NAME key?
Code below should explain what am i want (see BaseObject.attributes):
Code:
@Entity
@Table(name = "BASE_OBJECT")
class BaseObject {
@Id
@Column(name = "BASE_OBJECT_ID")
private Integer objectID;
// How can i do this?
// Keys are Attribute.name, joined by AttributeValue.baseObject
private Map<String, AttributeValue> attributes;
// getters/setters
}
@Entity
@Table(name = "ATTRIBUTE")
class Attribute {
@Id
@Column(name = "ATTRIBUTE_ID")
private Integer attributeID;
@Column(name = "NAME")
private String name;
// getters/setters
}
@Entity
@Table(name = "ATTRIBUTE_VALUE")
class AttributeValue {
@Id
@Column(name = "ATTRIBUTE_VALUE_ID")
private Integer attributeValueID;
@Column(name = "VALUE")
private String value;
@ManyToOne
@JoinColumn(name = "ATTRIBUTE_ID")
private Attribute attribute;
@ManyToOne
@JoinColumn(name = "BASE_OBJECT_ID")
private BaseObject baseObject;
//getters/setters
}