0

我有一个使用休眠验证器验证用户数据的代码。我有一些用户可能会输入我的程序的实体,它们是从抽象类“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;
}
}

这是抽象实体:

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
}
4

1 回答 1

0

我没有找到导致异常的确切原因,但我设法通过从 GenericRepository 中删除实现 PagingAndSortingRepository 来摆脱它,这对我的项目来说不是必需的。

于 2014-11-17T11:47:14.093 回答