I got stuck using snake case for variable name in Spring Boot

The following articles are subject to the following conditions

environment


Java:1.8
WebFramework:SpringBoot1.5.4
DB:MySQL

table


id int
name varchar
regist_date Date

The following error occurred when I added regist_date to the sort condition when fetching data from DB using findAll in Spring Boot.

No property regist found for type Entity class name with root cause

The cause was that I was using a snake case for variable names in the Entity class. According to DELIMITERS on line 39, lines 259 to 265 are split into regist and date. An error occurs when specifying conditions when sorting.

java:org.springframework.data.mapping.PropertyPath.java


39.	private static final String DELIMITERS = "_\\.";
40.	private static final String ALL_UPPERCASE = "[A-Z0-9._$]+";
41.	private static final Pattern SPLITTER = Pattern.compile("(?:[%s]?([%s]*?[^%s]+))".replaceAll("%s", DELIMITERS));

(abridgement)

253.	public static PropertyPath from(String source, TypeInformation<?> type) {
254.
255.		Assert.hasText(source, "Source must not be null or empty!");
256.		Assert.notNull(type, "TypeInformation must not be null or empty!");
257.
258.		List<String> iteratorSource = new ArrayList<String>();
259.		Matcher matcher = SPLITTER.matcher("_" + source);
260.
261.		while (matcher.find()) {
262.			iteratorSource.add(matcher.group(1));
263.		}
264.
265.		Iterator<String> parts = iteratorSource.iterator();

As a countermeasure, I changed what I wrote in the snake case to a camel case. I had guessed it when I saw the error,

--I want to match the variable name with the column name ――I don't want to change the policy even though the cause is not clear

I investigated it.

Also, if the column name is camel case, the variable name will match? (It is necessary to change hibernate's NamingStrategy in Spring Boot to EJB3NamingStrategy, but [Unverified]) There may be an opinion, but the column name should be a snake case, so leave it as it is

reference [[Additional correction] Precautions when specifying table name using Table annotation in Spring Boot JPA](http://mao-instantlife.hatenablog.com/entry/2015/07/29/JPA? Table annotation Use to point to the table name)

Recommended Posts

I got stuck using snake case for variable name in Spring Boot
I got stuck in File
What I got into @Transactional in Spring
[For beginners] I tried using DBUnit in Eclipse
[For beginners] I tried using JUnit 5 in Eclipse
Where I got stuck in today's "rails tutorial" (2020/10/05)
Where I got stuck in today's "rails tutorial" (2020/10/06)
Where I got stuck in today's "rails tutorial" (2020/10/04)
Where I got stuck in today's "rails tutorial" (2020/10/07)
I checked asynchronous execution of queries in Spring Boot 1.5.9
Test field-injected class in Spring boot test without using Spring container
I tried using an extended for statement in Java
I want to stop snake case in table definition
I got stuck in a clone of a two-dimensional array
I want to control the maximum file size in file upload for each URL in Spring Boot
Spring Boot Mybatis SQL Snake Case Column and Camel Case Mapping
Get error information using DefaultErrorAttributes and ErrorAttributeOptions in Spring Boot 2.3
I haven't understood after touching Spring Boot for a month
I tried to get started with Swagger using Spring Boot
I made a simple MVC sample system using Spring Boot
How to control transactions in Spring Boot without using @Transactional
Set context-param in Spring Boot
Spring Boot 2 multi-project in Gradle
Major changes in Spring Boot 1.5
NoHttpResponseException in Spring Boot + WireMock
Try using Spring Boot Security
Spring Boot for annotation learning
How to make a hinadan for a Spring Boot project using SPRING INITIALIZR
Uploading and downloading files using Ajax in Spring Boot (without JQuery)
Fitted in Spring Boot using a bean definition file named application.xml
What I did in the migration from Spring Boot 1.4 series to 2.0 series
What I did in the migration from Spring Boot 1.5 series to 2.0 series
Let's write a test code for login function in Spring Boot
I got stuck trying to write a where in clause in ActiveRecord
Unknown error in line 1 of pom.xml when using Spring Boot in Eclipse