JPA 2.0 : Exception to use javax.validation.* package in JPA 2.0

前端 未结 2 1372
感情败类
感情败类 2020-11-27 18:57

when i try to using bean validation with JPA using hibernate , the follwoing exception will occur :

Exception in thread \"main\" javax.persistence.Persistenc         


        
相关标签:
2条回答
  • 2020-11-27 19:17

    As @Korgen mentioned in comments hibernate-validator-5.x.x isn't compatible with validation-api-1.0.x. This is because of moving to new specification JSR-303 -> JSR-349.

    There are two ways to solve this issue:

    1. Downgrade hibernate validator version (which is implements JSR-303):

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.3.1.Final</version>
    </dependency> 
    

    2. If you don't want to move back from hibernate validator 5 to hibernate validator 4 another solution is to upgrade javax.validation to higher version (which is describe JSR-349):

    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.1.0.Final</version>
    </dependency>
    
    0 讨论(0)
  • 2020-11-27 19:26

    For those who got error NoClassDefFoundError: javax/validation/valueextraction/ValueExtractorDeclarationException and their validation-api was already javax.validation:validation-api:1.1.0.Final

    The fix was to upgrade from javax.validation:validation-api:1.1.0.Final to javax.validation:validation-api:2.0.1.Final.

    0 讨论(0)
提交回复
热议问题