i was wondering if it's possible to make custom hibernate validation annotation that will check in the database if the email exist or not (call dao method and return true if the email exist)
so i can do something like:
@NotBlank(message = "email is required")
@Email(message = "{invalid.email}")
@EmailExist(message = "{email.exist}")
@Column(name = "email", length = 155, nullable = false)
private String email;
please advise with a sample if possible, thanks in advance.
Yes it should be possible, you just need to implement your custom annotation validator implementation.
If you use real AspectJ and annotate the class with
@Configurable
then you an use@Inject
like in every other spring bean.@See:
No need for AspectJ magic. If you are using spring, you just need to @Autowire -annotate your field, spring will inject the DAO. See Spring Reference 5.7.2.2 Configuring Custom Constraints:
So your only job is to write the custom annotation. Easy to find samples on the web.