0

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
}
VedantK
  • 9,728
  • 7
  • 66
  • 71
raven
  • 775
  • 6
  • 22
  • looks like a dependency issue (version mismatch between hibernate-validator and faster-xml) –  Nov 15 '14 at 14:47
  • the dependency tree is as following: org.springframework.boot:spring-boot-starter-web:1.1.9.RELEASE org.hibernate:hibernate-validator:5.0.3.Final com.fasterxml:classmate:1.0.0 I've also tried using the latest version for each of both hibernate-validator and classmate – raven Nov 15 '14 at 15:14
  • my own guess is that since the exception contains "ResolvedRecursiveType", classmate might have some problem with this field in the Bank entity: public static Bank repo = new Bank(); – raven Nov 16 '14 at 10:49
  • I didn't see the "this code worked fine." part, sorry –  Nov 16 '14 at 11:03

1 Answers1

0

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.

raven
  • 775
  • 6
  • 22