So I'm not sure if this is a problem of SpringBoot as much as it is a problem of IntelliJ, but I thought I'd mention it here first. I recently made a simple POJO to represent Customers:
@Entity
public class Customer
{
@Id
private int customerId;
private int tId; // Supposed to represent a "team ID", written like this on purpose.
private String firstName, lastName;
// ...
// Setters, getters
// ...
Notice the name of the variable tId: One lowercase character followed by one uppercase and one lowercase character.
I create a CustomerRepository that extends CrudRepository and consult IntelliJ about how to generate some derived query method declarations:
Notice that IntelliJ generates the method name as findByTId, where the criteria is ByTId, with a capitalized T. Immediately when I accept that suggestion, IntelliJ warns me that this is probably not going to work:
and indeed, if I were to run the project, it compiles fine, but throws a succinct exception pretty fast:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerRepo': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.jason.springbootjpa.dao.CustomerRepo.findByTId(int)! No property TId found for type Customer! Did you mean 'tId'?
If I change the method name to findBytId, however, everything works fine and the project compiles and runs. I have tried the exact same pipeline by renaming tId to:
tID. I had the same issues.tiD. No issues. It seems that when the variable name begins with at least two lowercase letters, this issue does not arise.
Now I would be certain this would be an IntelliJ issue if it weren't for the following observation: I enabled queries by the field lastName with the derived query method declaration:
List<Customer> findByLastName(String lastName);
and everything worked fine, despite the capitalization of the variable's first letter. Curiously, findBylastName, with a lowercase l, works as well!
So I'm not sure if this is SpringBoot or Intellij related, and thought I'd mention it here before I do there.
Comment From: snicoll
If that was a problem with Spring, it wouldn't be a problem in Spring Boot as Spring Boot doesn't do anything with queries derived from method signatures (Spring Data does).
Looking at your report, IntelliJ IDEA is the one suggesting the version with a capital T. The fact it is followed immediately by a warning is an inconsistency in the Spring support in the IDE.
I am going to close this now for the reasons described above. Please report that to Jetbrains.