0

休止状態バリデーターを使用してユーザーデータを検証するコードがありました。ユーザーがプログラムに入力するエンティティがいくつかあり、それらは抽象クラス「AbstractEntity」から継承されます。このコードはうまくいきました。

しかし、その後、AbstractEntity に、自分が作成した別の抽象クラスを拡張させました。インターネットで何も見つからないという例外が発生しました。

例外を生成するコード行は次のとおりです。

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

1 に答える 1