Calling BrokenRepository.findById() fails at runtime:
InvalidDataAccessApiUsageException: Provided id of the wrong type for class com.luxoft.logeek.entity.SimpleEntity. Expected: class java.lang.Integer, got class java.lang.Long; nested exception is java.lang.IllegalArgumentException: Provided id of the wrong type for class com.luxoft.logeek.entity.SimpleEntity. Expected: class java.lang.Integer, got class java.lang.Long
In fact we can specify any instance of Serializable as ID type of JpaRepository and some of the methods (e.g. findAll()) are OK with that.
My suggestion is to add explicit check for ID at start-up time in order to fail applciation context: in this case the user becomes aware of broken repository immediately along with bad @Query declarations
DATAJPA-1654 Fix mismatch in tests between Repository declaration and the id type of the entity
DATACMNS-757 Verify identifier type declared on repository matches the one of the declared domain type
The text was updated successfully, but these errors were encountered:
This is related to DATACMNS-757, which is essentially asking for the same thing. We investigated this back in the days and had to roll this back as Hibernate is not properly returning identifier types from the JPA metamodel (which was reported here). Without that being fixed we'd cause a lot of applications not to start anymore if we deployed such a guard. If we produced warnings only people would get puzzled in the first place and very quickly ignore those as they're likely to contain false positives.
I suggest you make yourself heard at the Hibernate bug tracker. I briefly verified that the problem is still present in the latest Hibernate 5.4.10 as well as 6.0 Alpha 4