Can't run java validation (JSR 303)

天大地大妈咪最大 提交于 2019-12-06 04:43:21

I was facing similar problem. Actually, HibernatePersistence was not having ProviderUtil() method in entity jars. following combination works well.

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

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
 </dependency>

 <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.5.Final</version>
</dependency>

without list of JARs its quite hard to help you here. Do you have maven in your project?

If so, you can use `mvn dependency:tree and see the tree of jars.

It can be that you're using hibernate that doesn't conform the JPA 2.0 Specification ProviderUtil class was introduced in JPA 2.0 as the doc states: ProviderUtil

Yet another concern: Are you running standalone or inside some container (app/web server or something) If you're running a JBoss for example it has its own jars in the lib folder that can also clash with your jars. How exactly you're running your JUnit test?

If it's only a validation problem, consider using your own implementation of TraversableResolver instead of JPATraversableResolver or DefaultTraversableResolver. Here's how to do it.

JPATraversableResolver might cause an unwished dependency to JPA. Here's a guy with a similar problem.

Of course, if you expect your application to JPA2-compliant, this is not a solution.

public class MyTraversableResolver implements TraversableResolver {

     public boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class rootBeanType, Path pathToTraversableObject, ElementType elementType) {
        return true;
     }

     public boolean isCascadable(Object traversableObject, Path.Node traversableProperty, Class rootBeanType, Path pathToTraversableObject, ElementType elementType) {
        return true;
     }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!