我有一个使用休眠验证器验证用户数据的代码。我有一些实体,用户可以输入我的程序,它们是从抽象类“ AbstractEntity”继承的。此代码工作正常。
但是后来我让AbstractEntity扩展了我编写的另一个抽象类。我现在遇到一个例外,就是我在Internet上找不到任何东西。
这是产生异常的代码行:
Set<ConstraintViolation<AbstractEntity>> constraintViolations = validator.validate(abstractEntity, Default.class, Insert.class);
这是产生异常的一个示例实体:
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;
}
}
这是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;
}
}
这是AbstractEntity扩展的GenericRepository:
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
}
我没有找到导致异常的确切原因,但是我通过从GenericRepository中删除了对我的项目不是必需的工具PagingAndSortingRepository设法摆脱了异常。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句