我想在Map<Long, List<ItemAttribute>>
类内映射@Entity
,其中ItemAttribute本身是单独定义的@Entity
。
这是我用于映射的代码:
@Entity
@Table(name = "ITEM_ATTRIBUTE_GROUP")
public class ItemAttributeGroup implements Cloneable, Serializable
{
@ElementCollection
@MapKeyColumn(name="groupId")
@JoinTable(name = "ATTRIBUTES_IN_GROUP", joinColumns = @JoinColumn(name = "groupId"),
inverseJoinColumns = @JoinColumn(name = "ID"))
private Map<Long, List<ItemAttribute>> attributes = new HashMap<Long, List<ItemAttribute>>();
//getters and setters........
}
ItemAttribute是下面提到的一个单独的类:
@Entity
@Table(name = "ITEM_ATTRIBUTE")
public class ItemAttribute implements Cloneable, Serializable {
private static final long serialVersionUID = -8017036630979138942L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Long id;
@ElementCollection // this is a collection of primitives
@JoinTable(name="ATTRIBUTE_VALUE_RANGE", joinColumns=@JoinColumn(name="ID"))
@MapKeyColumn (name="RANGE_ID")// column name for map "key"
@Column(name="VALUE")// column name for map "value"
private Map<String, String> attributeValueRange = new HashMap<String, String>();
@ElementCollection // this is a collection of primitives
@JoinTable(name="QUALIFIER_VALUE_RANGE", joinColumns=@JoinColumn(name="ID"))
@MapKeyColumn (name="RANGE_ID")// column name for map "key"
@Column(name="VALUE")// column name for map "value"
private Map<String, String> qualifierValueRange = new HashMap<String, String>();
public Map<String, String> getAttributeValueRange() {
return attributeValueRange;
}
public void setAttributeValueRange(Map<String, String> attributeValueRange) {
this.attributeValueRange = attributeValueRange;
}
public Map<String, String> getQualifierValueRange() {
return qualifierValueRange;
}
public void setQualifierValueRange(Map<String, String> qualifierValueRange) {
this.qualifierValueRange = qualifierValueRange;
}
}
问题出在我无法识别的代码中。
我收到此错误
使用@ JoinTable.inverseJoinColumns定位未映射的类:
ItemAttributeGroup.attributes [java.util.List]
最佳答案
您需要创建一个中间类ItemAttributes。
@Entity
public class ItemAttributes {
@OneToMany
private List<ItemAttribute> attributes;
}
@Entity
public class ItemAttributeGroup implements Cloneable, Serializable {
@OneToMany
private Map<Long, ItemAttributes> attributesMap;
}