Our project is a Spring Boot 2.7 project with a dependency on spring-boot-starter-data-jpa, lombok, MapStruct and other libraries. Building the project with (Maven 3.6.2, JDK 17.0.2)
mvn clean package -Pdevelopment
produces a .war file which, when deployed to Tomcat 9.0.64, throws under certain conditions the following exception
org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing
This same project, when built and deployed to the same Tomcat by IntelliJ (in the most straightforward way), does not, under the same conditions, throw this exception.
Comparing the binary files in the two .war files, I see, for instance, that all these $$_hibernate_read
, $$_hibernate_write
, present in a .class file from the .war file generated by mvn package
:
are completely absent in the corresponding .class file from the .war file generated by the default build process of IntelliJ. I did not have much success in understanding what is this default build process precisely, but at least it uses the same Java version, the image of the build process in Process Explorer being something like:
D:\jvm\jdk-17.0.2\bin\java.exe -Xmx700m ......... D:/IntelliJ IDEA 2022.2/plugins/ant/lib/ant-jps.jar;D:/IntelliJ IDEA 2022.2/plugins/maven/lib/maven-jps.jar;D:/IntelliJ IDEA 2022.2/plugins/gradle-java/lib/gradle-jps.jar;D:/IntelliJ IDEA 2022.2/plugins/JPA/lib/jps/javaee-jpa-jps.jar" org.jetbrains.jps.cmdline.BuildMain 127.0.0.1 64013 5bf45946-3060-4d79-96c2-8e1a83c92574 C:/Users/..../AppData/Local/JetBrains/IntelliJIdea2022.2/compile-server
The error org.springframework.dao.InvalidDataAccessApiUsageException
by itself does not worry me very much, but the behavior is quite bothering since this means that I cannot really trust IntelliJ to catch such errors, and I really should deploy and test related features on Tomcat manually before releasing them.
Can I configure the IntelliJ build process so that it produces the .war artifact by running "mvn clean package" instead of its custom build process? Or perhaps I am just doing something in a wrong way?