Spring Data JPA Unable to locate Attribute with the the given name

老子叫甜甜 提交于 2019-12-04 03:44:49

Try changing private String FirstName,LastName,Email; to private String firstName,lastName,email;

It should work.

findByFirstName in SubscriberRepository tries to find a field firstName by convention which is not there.

As per specification , the property names should start with small case.

...The resolution algorithm starts with interpreting the entire part (AddressZipCode) as the property and checks the domain class for a property with that name (uncapitalized)....

It will try to find a property with uncapitalized name. So use firstName instead of FristName and etc..

The same problem was when i had deal with Spring Data Specifications (https://www.baeldung.com/rest-api-search-language-spring-data-specifications)

Initial piece of code was:

private Specification<Project> checkCriteriaByProjectNumberLike(projectNumber: String) {
    (root, query, criteriaBuilder) -> criteriaBuilder.like(root.get("project_number"), "%" + projectNumber)
}

The problem was in root.get("project_number"). Inside the method, I had to put the field name as in the model (projectNumber), but I sent the field name as in the database (project_number).

That is, the final correct decision was:

private Specification<Project> checkCriteriaByProjectNumberLike(projectNumber: String) {
    (root, query, criteriaBuilder) -> criteriaBuilder.like(root.get("projectNumber"), "%" + projectNumber)
}

After I change my entity class variables from capital letter to small letter for instance Username to username the method Users findByUsername(String username); is working for me now .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!