Java validation fails (JSR 303)

Recently, I decided to use JSR 303 to test the bean in our project, but when I run the JUNI test, it got an error. The log is as follows:

java.lang.AbstractMethodError: org.hibernate.ejb.HibernatePersistence.getProviderUtil()Ljavax/persistence/spi/ProviderUtil; at javax.persistence.Persistence$1.isLoaded(Persistence.java:78) at org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:61) at org.hibernate.validator.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:131) at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:46) at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:1242) at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:448) at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:397) at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:361) at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:313) at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:139) at com.icil.service.validator.BeanValidator.validate(BeanValidator.java:74) at com.icil.sofs.booking.model.ValidateTest.test1(ValidateTest.java:48) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99) at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75) at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45) at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71) at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35) at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 

Someone told me that this is due to conflicting JAR files. But I do not know which JARs contradict each other. Can someone tell me which JAR files are conflicting. Any help is huge for me, thanks !!!

enter image description here

enter image description here

enter image description here

+2
source share
3 answers

I had a similar problem. In fact, HibernatePersistence did not have a ProviderUtil () method in entity banks. The 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> 
0
source

without a JAR list, its pretty hard to help you here. Do you have maven in your project?

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

Perhaps you are using hibernation that does not meet the specification specification of JPA 2.0. The ProviderUtil class was introduced in JPA 2.0 because the document states: ProviderUtil

Another problem: you work autonomously or inside a container (application / web server or something else) If you use JBoss, for example, it has its own banks in the lib folder, which can also interfere with your jars. How exactly do you use your JUnit test?

0
source

If this is just a validation issue, consider using your own implementation of TraversableResolver instead of JPATraversableResolver or DefaultTraversableResolver. Here's how to do it .

JPATraversableResolver may cause unwanted JPA dependency. Here is a guy with a similar problem.

Of course, if you expect your application to be compatible with JPA2, 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; } } 
0
source

Source: https://habr.com/ru/post/1013224/


All Articles