From 8eedae811938ebd02e54d60d288e361dcea066b6 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 26 May 2026 21:21:49 +0000 Subject: [PATCH] fix: remove @NotNull from ManyToOne fields and use Integer in BrandDto - Remove @NotNull from catalogType and catalogBrand ManyToOne fields in CatalogItem. Spring MVC form binding does not resolve JPA relationships, so these were always null causing @Valid to always fail. Database-level enforcement via @JoinColumn(nullable=false) is retained. - Change BrandDto.id from primitive int to Integer to match CatalogBrand.getId() return type and avoid NPE on auto-unboxing. --- .../main/java/com/eshop/catalog/domain/entity/CatalogItem.java | 2 -- .../src/main/java/com/eshop/catalog/dto/BrandDto.java | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/eShopLegacyMVC-SpringBoot/src/main/java/com/eshop/catalog/domain/entity/CatalogItem.java b/eShopLegacyMVC-SpringBoot/src/main/java/com/eshop/catalog/domain/entity/CatalogItem.java index efbc0522..9ce00c0b 100644 --- a/eShopLegacyMVC-SpringBoot/src/main/java/com/eshop/catalog/domain/entity/CatalogItem.java +++ b/eShopLegacyMVC-SpringBoot/src/main/java/com/eshop/catalog/domain/entity/CatalogItem.java @@ -50,7 +50,6 @@ public class CatalogItem { @Column(name = "CatalogTypeId", insertable = false, updatable = false) private int catalogTypeId; - @NotNull @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "CatalogTypeId", nullable = false) private CatalogType catalogType; @@ -58,7 +57,6 @@ public class CatalogItem { @Column(name = "CatalogBrandId", insertable = false, updatable = false) private int catalogBrandId; - @NotNull @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "CatalogBrandId", nullable = false) private CatalogBrand catalogBrand; diff --git a/eShopLegacyMVC-SpringBoot/src/main/java/com/eshop/catalog/dto/BrandDto.java b/eShopLegacyMVC-SpringBoot/src/main/java/com/eshop/catalog/dto/BrandDto.java index 74d84b3e..366b24d6 100644 --- a/eShopLegacyMVC-SpringBoot/src/main/java/com/eshop/catalog/dto/BrandDto.java +++ b/eShopLegacyMVC-SpringBoot/src/main/java/com/eshop/catalog/dto/BrandDto.java @@ -1,4 +1,4 @@ package com.eshop.catalog.dto; -public record BrandDto(int id, String brand) { +public record BrandDto(Integer id, String brand) { }