覆盖休眠验证器注释?
我想覆盖休眠验证器中的约束。这是我的基类:
@Entity
@Table(name = "Value")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "valueType", discriminatorType = DiscriminatorType.STRING)
public abstract class Value extends CommonTable
{
private String equation;
@SimpleEquation(equationType = EquationType.EQUATION)
public String getEquation()
{
return equation;
}
public void setEquation(String equation)
{
this.equation = equation;
}
}
我有一个子类,我想在其中指定方程字段的equationType为EquationType.ANOTHER_EQUATION,如下所示:
@Entity(name = "CharacteristicUpgradeValue")
@DiscriminatorValue("CharacteristicUpgradeValue")
public class CharacteristicUpgradeValue extends Value
{
@Override
@SimpleEquation(equationType = EquationType.COST_VALUE)
public String getEquation()
{
return super.getEquation();
}
}
此代码抛出一个异常,表示我有一个org.hibernate.MappingException :实体映射中重复的列(正常,由于重复的 getter)
Hibernate/jpa 中有一个 @AttributeOverride 但它似乎只在列覆盖的情况下运行,而不是这种属性。
我该怎么办?
谢谢
I would like to override a constraint in hibernate validator. Here is my base class:
@Entity
@Table(name = "Value")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "valueType", discriminatorType = DiscriminatorType.STRING)
public abstract class Value extends CommonTable
{
private String equation;
@SimpleEquation(equationType = EquationType.EQUATION)
public String getEquation()
{
return equation;
}
public void setEquation(String equation)
{
this.equation = equation;
}
}
I've got a child class where I want to specify that the equationType for equation field is EquationType.ANOTHER_EQUATION, something like this:
@Entity(name = "CharacteristicUpgradeValue")
@DiscriminatorValue("CharacteristicUpgradeValue")
public class CharacteristicUpgradeValue extends Value
{
@Override
@SimpleEquation(equationType = EquationType.COST_VALUE)
public String getEquation()
{
return super.getEquation();
}
}
this code throw an exception saying that I've got a org.hibernate.MappingException: Repeated column in mapping for entity (normal, due to the duplicate getter)
There is an @AttributeOverride in Hibernate/jpa but it seems to run only with column override and not this kind of attribute.
How can I do it ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯...我找到了一个实现它的技巧...这不是很干净...但它运行:
这是我的基类:
您需要将 getter 指定为 @Transient 因为如果没有,Hibernate 将抛出一个方程场的重复定义。我的方程域现在受到保护,而不是私有的。
现在,在每个子类上,您可以通过指定约束来重写 getEquation(并且由于子类不继承 @Transient,因此重写的 getEquation 将用于方程字段映射)。
这是一个子类示例:
我还没有找到更好的......
Well... I've found a tip to achieve it... That's not very clean... but it runs:
here is my base class:
You need to specify the getter as @Transient because if not, Hibernate will throw a duplicate definition for the equation field. My equation field is now protected and not private.
And now, on each of your subclass, you override the getEquation by specifying the constraint (and as @Transient is not inherited by subclasses, the overriden getEquation will be use for the equation field mapping).
Here is a subclass example:
I haven't found better...