Проверка ограничения бина вызывает стекоперемещение - PullRequest
0 голосов
/ 28 июня 2019

Попытка создать средство проверки соответствия, чтобы проверить, доступно ли электронное письмо для использования при регистрации с использованием аннотации.

Hibernate продолжает вызывать метод validate () для проверки сущности, которая вызывает исключение stackoverflow.

@Component
public class ValidatorAddingCustomizer implements HibernatePropertiesCustomizer {

    private final ObjectProvider<javax.validation.Validator> provider;

    public ValidatorAddingCustomizer(ObjectProvider<javax.validation.Validator> provider) {
        this.provider = provider;
    }

    public void customize(Map<String, Object> hibernateProperties) {
        Validator validator = provider.getIfUnique();

        if (validator != null) {
            hibernateProperties.put("javax.persistence.validation.factory", validator);
        }
    }
}

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = UniqueCompteEmailValidator.class)
@Target({ ElementType.TYPE })
public @interface UniqueCompteEmail {

    String message() default "{com.mssmfactory.bacsimulator.uniquecompteemail.message}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};
}

public class UniqueCompteEmailValidator implements ConstraintValidator<UniqueCompteEmail, Compte> {

    @Autowired
    private CompteRepository compteRepository;

    @Override
    public boolean isValid(Compte value, ConstraintValidatorContext context) {
        if (value != null) {
            System.out.println("here is the value: " + value);

            Compte persistedCompte = this.compteRepository.findByEmail(value.getEmail());

            System.out.println("compte: " + persistedCompte);

            return persistedCompte == null || value.getId() == persistedCompte.getId();
        } else
            return false;
    }
}

@Repository
public interface CompteRepository extends JpaRepository<Compte, Integer> {

    public Compte findByUsername(String username);

    public Compte findByEmail(String email);
}

вот значение:

com.mssmfactory.bacsimulator.persistance.domainmodel.authentification.CompteEtudiant@75b73d2a вот значение: com.mssmfactory.bacsimulator.persistanceДоменное имязначение: com.mssmfactory.bacsimulator.persistance.domainmodel.authentification.CompteEtudiant@75b73d2a здесь это значение: com.mssmfactory.bacsimulator.persistance.domainmodel.authentification.CompteEtudiant@75b73d2a здесь это значение: com.mssmfactory.bacsimulator.persistance.domainmodel.authentification.CompteEtudiant@75b73d2a здесь это значение: com.mssmfactory.bacsimulator.persistance.domainmodel.authentification.CompteEtudiant@75b73d2a вот значение: com.mssmfactory.bacsimulator.CompteEtudiant @ 75b73d2a здесь это значение: com.mssmfactory.bacsimulator.persistance.domainmodel.authentification.CompteEtudiant@75b73d2a здесь это значение: com.mssmfactory.bacsimulator.persistance.domainmodel.authentification.CompteEtudiant@ab2mssmfactory.bacsimulator.persistance.domainmodel.authentification.CompteEtudiant@75b73d2a здесь это значение: com.mssmfactory.bacsimulator.persistance.domainmodel.authentification.CompteEtudiant@75b73d2a здесь это значение:CompteEtudiant @ 75b73d2a вот значение: com.mssmfactory.bacsimulator.persistance.domainmodel.authentification.CompteEtudiant@75b73d2a вот этоlue: com.mssmfactory.bacsimulator.persistance.domainmodel.authentification.CompteEtudiant@75b73d2a здесь это значение: com.mssmfactory.bacsimulator.persistance.domainmodel.authentification.CompteEtudiant@75b73d2a вот значение: com.mssimfactpers.bac.domainmodel.authentification.CompteEtudiant@75b73d2a здесь это значение: com.mssmfactory.bacsimulator.persistance.domainmodel.authentification.CompteEtudiant@75b73d2a здесь это значение: com.mssmfactory.bacsimulator.persistance.domainmodel.authen2a_a 201 201@9-27 22: 34: 58.911 ОШИБКА 4616 --- [nio-8080-exec-2] oaccC [. [. [/]. [DispatcherServlet]: Servlet.service () для сервлета [dispatcherServlet] в контексте с путем []сгенерировано исключение [Ошибка отправки обработчика;вложенное исключение - java.lang.StackOverflowError] с коренной причиной

java.lang.StackOverflowError: null at org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMorthoser_Exorset_Ex_set_Ex_Ex_WORF_S_WORSE_Ex_Ex_Ex_WORSE_Ex_Ex_Words~ [spring-data-commons-2.1.8.RELEASE.jar: 2.1.8.RELEASE] at org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.doInvoke (RepositoryFactorySupport.jar): spring-data-commons-2.1.8.RELEASE.jar: 2.1.8.RELEASE] at org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.lambda $ invoke $ 3 (RepositoryFactorySupport.jpg).-data-Обще-2.1.8.RELEASE.jar: 2.1.8.RELEASE]at org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.invoke (RepositoryFactorySupport.java:595) ~ [spring-data-commons-2.1.8.RELEASE.jar: 2.1.8.REL в org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:186) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke (DefaultMethodInvokingMethodInterceptor.java:59) ~ [spring-data-commons-2.1.8.RELEASE.jar: 2.1.8.RELEASE] в org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:186) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction (TransactionAspectSupport.java:295) ~ [spring-tx-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.transaction.interceptor.TransactionInterceptor.invoke (TransactionInterceptor.java:98) ~ [spring-tx-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:186) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke (PersistenceExceptionTranslationInterceptor.java:139) ~ [spring-tx-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:186) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor $ CrudMethodMetadataPopulationMethodInterceptor.invoke (CrudMethodMetadataPostProcessor.java:1EL...8.E.j.8.E.1.E.1.R.1.E.1.R.1.E.1.1.8.E.E.1.1.8.E.E.1.1.8E-jR 2.1.E.1. в org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:186) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke (ExposeInvocationInterceptor.java:93) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:186) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke (SurroundingTransactionDetectorMethodInterceptor.java:61) ~ [spring-data-commons-2.1.8.RELEASE.jELE: 2.1.8.RasE в org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:186) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.aop.framework.JdkDynamicAopProxy.invoke (JdkDynamicAopProxy.java:212) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] на com.sun.proxy. $ Proxy149.findByEmail (Неизвестный источник) ~ [na: na] на com.mssmfactory.bacsimulator.annotations.email.UniqueCompteEmailValidator.isValid (UniqueCompteEmailValidator.java:21) ~ [classes /: na] на com.mssmfactory.bacsimulator.annotations.email.UniqueCompteEmailValidator.isValid (UniqueCompteEmailValidator.java:1) ~ [classes /: na] в org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateSingleConstraint (ConstraintTree.java:171) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] в org.hibernate.validator.internal.engine.constraintvalidation.SimpleConstraintTree.validateConstraints (SimpleConstraintTree.java:68) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] в org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints (ConstraintTree.java:73) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final]в org.hibernate.validator.internal.metadata.core.MetaConstraint.doValidateConstraint (MetaConstraint.java:127) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] в org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint (MetaConstraint.java:120) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] в org.hibernate.validator.internal.engine.ValidatorImpl.validateMetaConstraint (ValidatorImpl.java:552) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForSingleDefaultGroupElement (ValidatorImpl.java:515) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] в org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup (ValidatorImpl.java:485) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] в org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup (ValidatorImpl.java:447) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] в org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext (ValidatorImpl.java:397) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] в org.hibernate.validator.internal.engine.ValidatorImpl.validate (ValidatorImpl.java:173) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate (BeanValidationEventListener.java:116) ~ [hibernate-core-5.3.10.Final.jar: 5.3.10.Final] at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert (BeanValidationEventListener.java:80) ~ [hibernate-core-5.3.10.Final.jar: 5.3.10.Final] в org.hibernate.action.internal.EntityInsertAction.preInsert (EntityInsertAction.java:209) ~ [hibernate-core-5.3.10.Final.jar: 5.3.10.Final] в org.hibernate.action.internal.EntityInsertAction.execute (EntityInsertAction.java:83) ~ [hibernate-core-5.3.10.Final.jar: 5.3.10.Final] в org.hibernate.engine.spi.ActionQueue.executeActions (ActionQueue.java:604) ~ [hibernate-core-5.3.10.Final.jar: 5.3.10.Final] в org.hibernate.engine.spi.ActionQueue.executeActions (ActionQueue.java:478) ~ [hibernate-core-5.3.10.Final.jar: 5.3.10.Final] в org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions (AbstractFlushingEventListener.java:356) ~ [hibernate-core-5.3.10.Final.jar: 5.3.10.Final] в org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush (DefaultAutoFlushEventListener.java:50) ~ [hibernate-core-5.3.10.Final.jar: 5.3.10.Final] в org.hibernate.internal.SessionImpl.autoFlushIfRequired (SessionImpl.java:1415) ~ [hibernate-core-5.3.10.Final.jar: 5.3.10.Final] в org.hibernate.internal.SessionImpl.list (SessionImpl.java:1501) ~ [hibernate-core-5.3.10.Final.jar: 5.3.10.Final] в org.hibernate.query.internal.AbstractProducedQuery.doList (AbstractProducedQuery.java:1537) ~ [hibernate-core-5.3.10.Final.jar: 5.3.10.Final] в org.hibernate.query.internal.AbstractProducedQuery.list (AbstractProducedQuery.java:1505) ~ [hibernate-core-5.3.10.Final.jar: 5.3.10.Final] в org.hibernate.query.internal.AbstractProducedQuery.getSingleResult (AbstractProducedQuery.java:1553) ~ [hibernate-core-5.3.10.Final.jar: 5.3.10.Final] at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getSingleResult (CriteriaQueryTypeQueryAdapter.java:109) ~ [hibernate-core-5.3.10.Final.jar: 5.3.10.Final] в org.springframework.data.jpa.repository.query.JpaQueryExecution $ SingleEntityExecution.doExecute (JpaQueryExecution.java:214) ~ [spring-data-jpa-2.1.8.RELEASE.jar: 2.1.8.RELEASE] в org.springframework.data.jpa.repository.query.JpaQueryExecution.execute (JpaQueryExecution.java:91) ~ [spring-data-jpa-2.1.8.RELEASE.jar: 2.1.8.RELEASE]в org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute (AbstractJpaQuery.java:136) ~ [spring-data-jpa-2.1.8.RELEASE.jar: 2.1.8.RELEASE] в org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute (AbstractJpaQuery.java:125) ~ [spring-data-jpa-2.1.8.RELEASE.jar: 2.1.8.RELEASE] в org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.doInvoke (RepositoryFactorySupport.java:605) ~ [spring-data-commons-2.1.8.RELEASE.jar: 2.1.8.RELEASE] в org.springframework.dore.suposit.dore.supositRepositoryFactorySupport $ QueryExecutorMethodInterceptor.lambda $ invoke $ 3 (RepositoryFactorySupport.java:595) ~ [spring-data-commons-2.1.8.RELEASE.jar: 2.1.8.RELEASE] в org.springframework.dore.repositort.dore.repository.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.invoke (RepositoryFactorySupport.java:595) ~ [spring-data-commons-2.1.8.RELEASE.jar: 2.1.8.RELEASE] в org.springframework.aop.framework.hoceed (ReflectiveMethodInvocation.java:186) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke (DefaultMethodInvoteror) [DefaultMethodInvoteror]-data-commons-2.1.8.RELEASE.jar: 2.1.8.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:186) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction (TransactionAspectSupport.java:295) ~ [spring-tx-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в орг.springframework.transaction.interceptor.TransactionInterceptor.invoke (TransactionInterceptor.java:98) ~ [spring-tx-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.aop.framework.ReflectiveMethodInvocationProce.java: 186) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke (PersistenceExceptionTranslationInterceptor.java:139) ~ [spring-tx-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:6) - 18)-5.1.7.RELEASE.jar: 5.1.7.RELEASE] at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor $ CrudMethodMetadataPopulationMethodInterceptor.invoke (источник данных8.RELEASE.jar: 2.1.8.RELEASE] в org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:186) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke (ExposeInvocationInterceptor.java:93) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.aop.frameocetInhod.vle.proceed (ReflectiveMethodInvocation.java:186) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke (SurroundingTransactionDetectorMethodInterceptor.java:61) ~ [spring-data-commons-2.1.8.RELEASE.jar: 2.1.8.RELEASE] в org.springframework.aop.frameethope186) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в org.springframework.aop.framework.JdkDynamicAopProxy.invoke (JdkDynamicAopProxy.java:212) ~ [spring-aop-5.1.7.RELEASE.jar: 5.1.7.RELEASE] в com.sun.proxy. $ Proxy149.findByEmail (Неизвестный источник) ~ [na: na] в com.mssmfactory.bacsimulator.annotations.email.UniqueCompteEmailValidator.isValid (UniqueCompteEmailValidator.j: 21) ~ [классы /: нет]в com.mssmfactory.bacsimulator.annotations.email.UniqueCompteEmailValidator.isValid (UniqueCompteEmailValidator.java:1) ~ [classes /: na] в org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.valj) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] в org.hibernate.validator.internal.engine.constraintvalidation.SimpleConstraintTree.validateConstraints (SimpleConstraintTree.java:68) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints (ConstraintTree.java:73) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] at org.hibernate.validator.internal.metadata.core.MetaConstraint.doValidateConstraint (MetaConstraint.java:127) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final]в org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint (MetaConstraint.java:120) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] at org.hibernate.validator.internal.engine.ValidatorImpl.validateMetaConstraint (ValidatorImpl.java:552) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] в org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForSingleDefaultGroupElement (ValidatorImpl.java:515) ~ [hibernate-validator-6.0.16.Final.jar: 6.0.16.Final] в org.hibernate.validator.internal.engine.ValidatorImpl.vall..

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...