0
我正在使用Hibernate驗證器4.3。我嘗試驗證指定的實體:Hibernate驗證器URL和ConstraintViolationException
@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;
}
但我有問題,在Web表單,當commissionDecisionFileUrl空urlTitle被填滿,然後得到異常(否則驗證過程中正常工作):
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)
謝謝你的幫助。
如果我們知道驗證消息用英語說什麼,這會很有幫助。 –