Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

和HibernateValidator集成使用时 每次都需要 setHibernateValidator 太过麻烦 #30

Open
xiaolongyuan opened this issue Jan 23, 2018 · 1 comment

Comments

@xiaolongyuan
Copy link

        Result ret = FluentValidator.checkAll()
                .on(company, new HibernateSupportedValidator<Company>().setHibernateValidator(validator))
                .on(company, new CompanyCustomValidator())
                .doValidate().result(toSimple());

另外

public class HibernateSupportedValidator<T> extends ValidatorHandler<T> implements Validator<T> {
    private static javax.validation.Validator HIBERANTE_VALIDATOR;
    private int hibernateDefaultErrorCode;
    private ConstraintViolationTransformer constraintViolationTransformer = new DefaultConstraintViolationTransformer();

HIBERANTE_VALIDATOR 为static 何解?

@neoremind
Copy link
Owner

  1. Because Fluent-validator is not bounded to hibernate validator, so it is intend to be created manually. If you think setHibernateValidator is redundant, I suggest using Factory design pattern to build it, note that HibernateSupportedValidator is not thread-safe, must be prototyped.

  2. Validator instance is retrieved from the ValidatorFactory. Validator instances are thread-safe and may be reused multiple times. This is how we use Hibernate in the right way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants