ClassCastException with @Autowired Spring JpaRepositories #294

beatjost opened this Issue Jun 15, 2016 · 2 comments


None yet

2 participants

beatjost commented Jun 15, 2016 edited

We have several test which run until version 1.21 of JMockit. From version 1.22 we get a 'ClassCastException'. The problem there is that the spring JpaRepository retuns a repository instance itself instead of a generic domain class.


public interface StateRepository extends JpaRepository<State, Long> {

Runtime code

StateRepository stateRepo;
activity.setState(stateRepo.findOne(stateId));  //returns repo instead of domain pojo

JUnit test

StateUpdater stateUpdater;
StateRepository stateRepo;

@rliesenfeld rliesenfeld added the bug label Jun 15, 2016
@rliesenfeld rliesenfeld self-assigned this Jun 15, 2016

It's a bug.

Thanks for reporting!

@rliesenfeld rliesenfeld added a commit that closed this issue Jun 19, 2016
@rliesenfeld rliesenfeld Fixed bug in cascaded mocking, involving a multi-level hierarchy of g…
…eneric interface types, where a ClassCastException was occurring; closes #294.

Thanks for fast fixing - will check next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment