Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository with wrong ID doesn't fail start-up of application context [DATAJPA-1649] #1953

Closed
spring-projects-issues opened this issue Dec 26, 2019 · 3 comments
Assignees
Labels
in: core Issues in core support status: declined A suggestion or change that we don't feel we should currently apply type: bug A general bug

Comments

@spring-projects-issues
Copy link

Сергей Цыпанов opened DATAJPA-1649 and commented

Suppose we have an entity

@Entity
public class SimpleEntity {
  @Id
  private int id; // <---

  @Column
  private String name;
}

and repository

public interface BrokenRepository extends JpaRepository<SimpleEntity, Long> {
}

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


Issue Links:

  • 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

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

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

@spring-projects-issues
Copy link
Author

Сергей Цыпанов commented

Oliver Drotbohm I'll then revert ID check in my PR here: #403

Should I though keep the changes that  set correct ID for repositories declared in tests?

@spring-projects-issues
Copy link
Author

Jens Schauder commented

Since we can't fix the issue described here I close this bug.
But I have created a separate issue, which I will use to merge your PR with the ID fixes

@spring-projects-issues spring-projects-issues added type: bug A general bug status: declined A suggestion or change that we don't feel we should currently apply in: core Issues in core support labels Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support status: declined A suggestion or change that we don't feel we should currently apply type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants