The biggest pitfall of SpringBoot DevTools, none of them
Recently, a lot of changes have been added to the SpringBoot project, and then I encountered a very strange problem.
HibernateDatabase query error
This is simply weird
Expected type and actual value are exactly the same, but Hibernate thinks they are different. How can this be fixed?
After struggling with this strange problem for a day, I found that this only occurs on my local machine. The same code is completely normal on the test server.
At least there was a breakthrough, and I suspected it was an environmental problem, so I started to unify the MySQL version and the Java version, but it had no effect at all.
Just when I was about to give up, I saw the bottom of the error log again.
It seems to be an error reported by the bottom layer of JDK, so interrupt and take a look.
After debugging with breakpoints, I made a major discovery! ! !
2021-03-03 17:08:28.016 ERROR 36216 --- [ XNIO-2 task-1] o.h.p.access.spi.SetterMethodImpl : HHH000123: IllegalArgumentException in class: net.margrop.racentity.entity.Race, setter method of property: raceType
2021-03-03 17:08:28.016 ERROR 36216 --- [ XNIO-2 task-1] o.h.p.access.spi.SetterMethodImpl : HHH000091: Expected type: net.margrop.raceapi.entity.permanent.RaceType, actual value: net.margrop.raceapi.entity.permanent.RaceType
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.hibernate.property.access.spi.SetterMethodImpl.set(SetterMethodImpl.java:45)
ClassLoader is inconsistent
Two ClassLoader of the same class, one is AppClassLoader and the other is RestartClassLoader.
I just happened to learn JVM recently, and the key knowledge points emerged.
For two Class to be equal, they need to have the same package name, and the same for ClassLoader
AppClassLoader I know what it is, but what the hell is RestartClassLoader?
Search RestartClassLoader AppClassLoader in Google, and the truth finally emerged. The first page is full of these questions.
It seems that DevTools has tricked a lot of people~
Solution
Delete the dependency of spring-boot-devtools in pom.xml.