javaspring-bootspring-data-jpahungarian-notation

Hungarian Notation and Spring JpaRepositories


I am using Hungarian notation to declare attributes, and this is causing me some conflict with Spring Data's Jpa repositories. Since this implies that the private attributes contain the _ character at the beginning, when writing a named query to get certain data from the database I get an error, indicating the following:

No property 'orderBy' found for type 'Operation'.

I have suspicions that this happens because the _ character is reserved in Spring Data, and I can think of a way to fix it, but it is not efficient at all.

The method that throws the error is the following:

List findTop7ByOrderBy_tTimestampAsc();

Where _tTimestamp is an attribute of type LocalDateTime.

I have tried to escape the _ character by using another one just before it (i.e., the method would be named findTop7ByOrderBy__tTimestampAsc), but it still throws the same error. I have also tried using the name I give it in the @Column annotation in the class declaration, and this way I get the following error:

No property 'timestamp' found for type 'Operation' Did you mean ''_tTimestamp''

But even so, if I write as it is indicated there, I return to the first step, which still throws me error.

I would like to know if there is any way to fix this without getting rid of the Hungarian notation.


Solution

  • Spring Datas query derivation is build on top of the Java coding convention. If you (or your prof) decide not to use that you are basically opting out of that feature.

    I try not to comment on the merit of Hungarian notation in Java.