I am writing my own constraint. So I need class name and field name in my validator to run HQL in it.
public class MyValidator implements ConstraintValidator<check, Object> {
@Autowired
private MyDaoImpl myDaoImpl;
@Override
public void initialize(check uniChk) {
}
@Override
public boolean isValid(Object entity, ConstraintValidatorContext ctx) {
//Need Class name and field name
objList = myDaoImpl.getDataByColumnName(classname, fieldname, entity.toString());
// some condition
return isValid;
}
constraint name is @check.
I saw something like ConstrainedElementKind, ConstrainedElement interface. I believe anyhow I can get it using it but couldn't find any example of it. I want to make it generic (no hardcoding of class or variable name ).
What can be the way to get this values?
Aucun commentaire:
Enregistrer un commentaire