0

我有一个字段:Ordinality DB: ORDINALITY NOT NULL NUMBER(2)

@Column(name="ORDINALITY")
@NotNull(message="Ordinality is Mandatory")
@Size(max=2,message="Ordinality exceeded the limit, Max. 2 numbers are allowed.")
private BigDecimal ordinality;
  1. 我只想将条目限制为数字,确切的注释语法是什么。
  2. 当我给出适当的值以及不给出任何值并提交页面时,我遇到了错误。
javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.math.BigDecimal.
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.verifyResolveWasUnique(ConstraintValidatorManager.java:218)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.findMatchingValidatorClass(ConstraintValidatorManager.java:193)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.getInitializedValidator(ConstraintValidatorManager.java:97)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:125)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:91)
    at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:83)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:547)
4

1 回答 1

1

要设置基础数据库字段的精度,您应该使用@Column注释的精度和比例元素。

@Column(precision=10, scale=2)

要验证数字,请使用@DecimalMax注释。

@DecimalMax("30.00")
于 2015-09-03T12:08:38.683 回答