0

Hibernate バリデーター 4.3 を使用しています。指定されたエンティティを検証してみます:

@Entity
@Table(name = "standard_group")
    public class StandardGroup extends AbstractEntity {

    private static final long serialVersionUID = 1985481354L;
    private Long id;
    private String groupName;
    private String commissionDecisionFileUrl;
    private String urlTitle;

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }

    @NotEmpty(message = "custom error text")
    @Column(name = "grup_name")
    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    @URL(message = "custom error text") 
    @Column(name = "comission_decision_file_url")
    public String getCommissionDecisionUrl() {
        return commissionDecisionFileUrl;
    }

    public void setCommissionDecisionUrl(String commissionDecisionUrl) {
        this.commissionDecisionFileUrl = commissionDecisionUrl;
    }

    @Column(name = "url_title", length = 25)
    @Length(max = 25, message = "custom error text")
    public String getUrlTitle() {
        return urlTitle;
    }

    public void setUrlTitle(String urlTitle) {
        this.urlTitle = urlTitle;
    }

しかし、commissionDecisionFileUrlが空でurlTitleが入力されている場合、Web フォームに問題があり、例外が発生します (それ以外の場合、検証プロセスは正常に機能します)。

javax.validation.ConstraintViolationException: Validation failed for classes [sk.peterjurkovic.cpr.entities.StandardGroup] during update time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
    ConstraintViolationImpl{interpolatedMessage='Odkaz na soubor ma chybný tvar', propertyPath=commissionDecisionUrl, rootBeanClass=class sk.peterjurkovic.cpr.entities.StandardGroup, messageTemplate='Odkaz na soubor ma chybný tvar'}
]
    org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:159)
    org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreUpdate(BeanValidationEventListener.java:102)
    org.hibernate.action.internal.EntityUpdateAction.preUpdate(EntityUpdateAction.java:235)
    org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:115)
    org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
    org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
    org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:276)
    org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
    org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
    org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1213)

助けてくれてありがとう。

4

1 に答える 1

2

与えられた情報に基づいて、確実に判断するのは困難です。org.hibernate.validator.constraints.impl.URLValidator.isValid(String, ConstraintValidatorContext)ブレークポイントを設定して、入力が有効でない理由を自分で確認することをお勧めします。

于 2013-01-01T20:13:44.663 に答える