• 使用spring jpa hibernate框架时报错:javax.validation.UnexpectedTypeException: HV000030


    错误信息:

    [#%&*^]20190521121942:497.!react:all.,RctJobExecutor-1#D9AA5167921A464CA9DDA14943545426%NA&*A^:WARN>org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction
    	at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:526)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:484)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
    
    ...
    
    Caused by: javax.persistence.RollbackException: Error while committing the transaction
    	at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:94)
    	at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
    	... 29 more
    Caused by: javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.Size' validating type 'com.x.pss.react.dao.domain.protect.support.IsSupportReturn'. Check configuration for 'isSupportReturn'
    	at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.throwExceptionForNullValidator(ConstraintTree.java:229)
    	at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getConstraintValidatorNoUnwrapping(ConstraintTree.java:310)
    	at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getConstraintValidatorInstanceForAutomaticUnwrapping(ConstraintTree.java:244)
    	at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getInitializedConstraintValidator(ConstraintTree.java:163)
    	at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:116)
    	at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateComposingConstraints(ConstraintTree.java:398)
    	at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:98)
    	at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:87)
    	at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:73)
    	at org.hibernate.validator.internal.engine.ValidatorImpl.validateMetaConstraint(ValidatorImpl.java:617)
    	at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:580)
    	at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForSingleDefaultGroupElement(ValidatorImpl.java:524)
    	at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:492)
    	at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:457)
    	at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:407)
    	at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:205)
    	at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:137)
    	at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:95)
    	at org.hibernate.action.internal.EntityInsertAction.preInsert(EntityInsertAction.java:218)
    	at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:97)
    	at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:465)
    	at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:351)
    	at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
    	at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
    	at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1258)
    	at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:425)
    	at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
    	at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
    	at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:77)

    查看代码和资料发现,在jpa实体类中,枚举类型字段isSupportReturn上加了@NotEmpty导致了这个问题

    查看@NotEmpty的源代码发现,@NotEmpty只能加在String、集合、数组上边,而且限制了最小长度为1,而像枚举类型、基本类型这样的字段是没有size这个特征的,所以不能使用@NotEmpty。

    当字段使用@NotEmpty时,在提交该字段时会校验字段,该字段必须包含具体内容,不能是null,对于字符串来说,不能为"";对于集合或数组来说,其中必须包含元素。

       

  • 相关阅读:
    Ruby的一些基本知识
    Seleniumwebdriver系列教程(七)————如何处理alert和confirm
    Seleniumwebdriver系列教程(八)————如何操作select下拉框
    Ruby 控制结构
    Seleniumwebdriver系列教程(十)————使用jquery辅助进行测试
    Ruby是一门面向对象语言
    Seleniumwebdriver系列教程(九)————如何智能的等待页面加载完成
    Ruby 正则表达式
    执行ajax成功后进行页面的刷新
    Nacos介绍与安装启动
  • 原文地址:https://www.cnblogs.com/xhj123/p/10899154.html
Copyright © 2020-2023  润新知