The StackOverflowError in your EnergyHourDetailJobConfiguration was not caused by recursive method calls or circular references, but rather by extremely long SQL strings being built and processed in memory.
This happened because
The SQL query contains hundreds of fields (INSERT ... ON CONFLICT ... DO UPDATE).
The query is built entirely in Java using StringBuilder.append() calls.
The query is logged in full using log.info(), which forces the JVM to create a huge string for logging.
Logging overhead
Driver limitations
Memory usage
OutOfMemoryError.StackOverflowError.Instead of:
log.info(">>>>> query : " + sql);
Use:
if (sql.length() > 2000) {
log.info("SQL length: {}", sql.length());
log.debug("SQL preview: {}...", sql.substring(0, 500));
} else {
log.info("SQL: {}", sql);
}
This logs only the length and a short preview.
Store the SQL in src/main/resources/sql/energy_hour_detail_insert.sql and load it:
String sql = Files.readString(Paths.get("classpath:sql/energy_hour_detail_insert.sql"));
Advantages:
Cleaner Java code.
Easier SQL maintenance.
No huge inline strings in Java.
Instead of hardcoding hundreds of .append() calls, store field names in arrays and use:
String insertFields = String.join(",", fieldList);
String updateFields = fieldList.stream()
.map(f -> f + " = EXCLUDED." + f)
.collect(Collectors.joining(", "));
This reduces code size and makes changes easier.
ON CONFLICT DO UPDATEIf some fields rarely change, exclude them from the update clause to shorten the SQL.
The error was caused by overly long SQL strings being built and logged.
To fix:
Limit SQL logging.
Move SQL to external files.
Use dynamic generation for repetitive field lists.
Consider reducing the number of fields in the query.