我想用 Hibernate 映射超类中的通用字段。
我的妈妈班是:
@Entity
@Table(name = "ParameterValue")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "parameterType", discriminatorType = DiscriminatorType.STRING)
public abstract class ParameterValue<C>
{
private C value;
/* HELP NEEDED HERE */
public C getValue()
{
return value;
}
public void setValue(C value)
{
this.value = value;
}
}
一个子类:
@Entity
@DiscriminatorValue(value = "integer")
@AttributeOverride(name = "value", column = @Column(name = "intValue"))
public class IntegerParameterValue extends ParameterValue<Integer>
{
}
正如您所看到的,我覆盖了值字段以指定要在数据库中使用的列。
我的表 ParameterValue 由几列组成,每种类型一列。
CREATE TABLE `ParameterValue` (
`intValue` int(11) DEFAULT NULL,
`doubleValue` double DEFAULT NULL,
`stringValue` text
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
但 hibernate 抱怨说:
ParameterValue.value has an unbound type and no explicit target entity. Resolve this Generic usage issue or set an explicit target attribute (eg @OneToMany(target=) or use an explicit @Type
好的,但是超类中 getValue 的良好配置是什么? (我已经发表了“这里需要帮助”的评论)