From 2e8af3b1d28aa2844610d3200bef8c0b921101f2 Mon Sep 17 00:00:00 2001 From: Tour Date: Sun, 7 Dec 2025 13:10:39 +0100 Subject: [PATCH] Fix PRIMARY KEY constraint handling in auction import - Handle both auction_id and URL constraint failures - Add fallback UPDATE by URL when INSERT fails - Properly catch and log constraint violations without propagating - Fixes import errors on server with duplicate auctions Former-commit-id: 80b9841aee79c9090139aaa5f9f56afab2cdec72 --- src/main/java/auctiora/DatabaseService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/auctiora/DatabaseService.java b/src/main/java/auctiora/DatabaseService.java index 8f056d6..646da3e 100644 --- a/src/main/java/auctiora/DatabaseService.java +++ b/src/main/java/auctiora/DatabaseService.java @@ -481,6 +481,9 @@ public class DatabaseService { } else { log.debug("Updated existing auction by URL: {}", auction.url()); } + } catch (SQLException updateEx) { + // UPDATE also failed - log and swallow the exception + log.warn("Failed to update auction by URL ({}): {}", auction.url(), updateEx.getMessage()); } } else { throw e; @@ -844,8 +847,12 @@ public class DatabaseService { } upsertAuction(auction); imported.add(auction); + } catch (SQLException e) { + // SQLException should be handled by upsertAuction, but if it propagates here, log it + log.warn("Failed to import auction (SQL error): {}", e.getMessage()); } catch (Exception e) { - System.err.println("Failed to import auction: " + e.getMessage()); + // Other exceptions (parsing errors, etc) + log.warn("Failed to import auction (parsing error): {}", e.getMessage()); } } } catch (SQLException e) {