hibernate-validator unnecessarily calls the thread-unsafe CachingJPATraversableResolverForSingleValidation in hibernate-core when validating

Description

We use hibernate-validator to validate REST request body param。And it has nothind deal with hibernate-core. But recently we add new component "hibernate-core" into our project to do something about data persistence. Then we accidently found that our service threads were permanently fall into a "while" loop.
The stack is here:
----------------stack begin--------------------------------------------------------------------------------
"auth-catalina-exec-3" #98 daemon prio=5 os_prio=0 tid=0x000055cf9c4de7c0 nid=0x25067 runnable [0x00007f77d6bfb000]
java.lang.Thread.State: RUNNABLE
at java.util.WeakHashMap.get(WeakHashMap.java:403)
at org.hibernate.jpa.internal.util.PersistenceUtilHelper$MetadataCache.getClassMetadata(PersistenceUtilHelper.java:422)
at org.hibernate.jpa.internal.util.PersistenceUtilHelper.isLoadedWithReference(PersistenceUtilHelper.java:214)
at org.hibernate.jpa.HibernatePersistenceProvider$1.isLoadedWithReference(HibernatePersistenceProvider.java:186)
at javax.persistence.Persistence$PersistenceUtilImpl.isLoaded(Persistence.java:155)
at org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:52)
at org.hibernate.validator.internal.engine.resolver.CachingJPATraversableResolverForSingleValidation.lambda$isReachable$0(CachingJPATraversableResolverForSingleValidation.java:43)
at org.hibernate.validator.internal.engine.resolver.CachingJPATraversableResolverForSingleValidation$$Lambda$844/2026713638.apply(Unknown Source)
at java.util.HashMap.computeIfAbsent(HashMap.java:1127)
at org.hibernate.validator.internal.engine.resolver.CachingJPATraversableResolverForSingleValidation.isReachable(CachingJPATraversableResolverForSingleValidation.java:43)
at org.hibernate.validator.internal.engine.ValidatorImpl.isReachable(ValidatorImpl.java:1323)
at org.hibernate.validator.internal.engine.ValidatorImpl.isCascadeRequired(ValidatorImpl.java:1352)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:578)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:406)
at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:173)
----------------stack begin---------------------------------------------------------------------------------

We check the code and find the class "CachingJPATraversableResolverForSingleValidation" has a java doc notification: "It works only for a single validate* call and should not be used if {@code TraversableResolver} is accessed concurrently." We do have to call "ValidatorImpl.validate" concurrently, but we just use hibernate-validator to validating only, and didn't mean to use CachingJPATraversableResolverForSingleValidation.

My question is: Are there any way to use hibernate-validator only and don't let it to call anything about hibernate-core when validating params?

Environment

jdk8,linux
tomcat 7.x

Assignee

Unassigned

Reporter

zhaowenxishi

Labels

None

Feedback Requested

2020/05/19

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Affects versions

Priority

Major
Configure