I had a code that validated the users data using hibernate validator. I have some entities that the user might input my program and they are inherited from an abstract class "AbstractEntity". this code worked fine.
but then I made AbstractEntity extend another abstract class that I wrote. I now get an exception that I cannot find anything about in the Internet.
Here is the line of code that produces the exception:
Set<ConstraintViolation<AbstractEntity>> constraintViolations = validator.validate(abstractEntity, Default.class, Insert.class);
here's one example entity that produces the exception:
public class Bank extends AbstractEntity<Bank>{
public static Bank repo = new Bank();
@NotNull(groups = Insert.class)
private String name; // with getters and setters
protected Bank repo(){
return repo;
}
}
this is AbstractEntity:
public abstract class AbstractEntity<T extends AbstractEntity> extends GenericRepository<T>{
@Min(1)
@NotNull(groups = Update.class)
protected Long id; // with getters and setters
protected abstract T repo();
public String update(){
repo().update(this);
return null;
}
public String delete(){
repo().delete(id);
return null;
}
public String save(){
repo().save(this);
return null;
}
}
this is GenericRepository which AbstractEntity extends:
public abstract class GenericRepository<T extends AbstractEntity> extends ApplicationContextAwareBean implements PagingAndSortingRepository<T, Long>{
private Class<T> aClass = (Class<T>) this.getClass();
private String tableName = aClass.getSimpleName().toLowerCase();
private RowMapper<T> rowMapper = new BeanPropertyRowMapper<>(aClass);
private JdbcTemplate jdbcTemplate = (JdbcTemplate) ac.getBean("JdbcTemplate");
// also implements all methods from PagingAndSortingRepository
}
I didn't find what exactly causes the exception but I managed to get rid of it by removing the implements PagingAndSortingRepository from GenericRepository which was not necessary for my project.