我有 POJO,我需要在其中通过注释映射 MAP 字段。我正在尝试下面的代码。
@Entity
@Table(name = "ITEM_ATTRIBUTE", catalog = "DataSync")
public class ItemAttribute implements Cloneable, Serializable {
@ElementCollection(targetClass = AttributeValueRange.class)
@MapKeyColumn(name="rangeId")
@Column(name="value")
@CollectionTable(name="ATTRIBUTE_VALUE_RANGE", joinColumns=@JoinColumn(name="ITEM_ID"))
private Map<String, String> attributeValueRange;
}
我还为 Map 字段创建了一个单独的类。下面是AttributeValueRange
类
@Entity
@Table(name="ATTRIBUTE_VALUE_RANGE", catalog="datasync")
public class AttributeValueRange {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Long id;
private String rangeId;
private String value;
/**
* @return the rangeId
*/
public String getRangeId() {
return rangeId;
}
/**
* @param rangeId the rangeId to set
*/
public void setRangeId(String rangeId) {
this.rangeId = rangeId;
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* @param value the value to set
*/
public void setValue(String value) {
this.value = value;
}
/**
* @return the id
*/
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
}
我有以下错误堆栈跟踪
Caused by: org.springframework.orm.hibernate3.HibernateSystemException: could not get a field value by reflection getter of AttributeValueRange.id; nested exception is org.hibernate.PropertyAccessException: could not get a field value by reflection getter of AttributeValueRange.id
Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of AttributeValueRange.id
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field AttributeValueRange.id to java.lang.String
请确定我在这里缺少什么?
我正在使用 ZK 框架、Spring 和 Hibernate