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