From a7b1dcb5e109424803a3e1365c5ac6aa034e28d1 Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 27 Apr 2026 19:47:19 +0200 Subject: [PATCH] fix(stammbaum): JOIN FETCH persons in relationship queries Both /api/network and /api/persons/{id}/relationships threw LazyInitializationException when toDTO read Person.getDisplayName(): the read-side service methods aren't @Transactional, so the session closed before the proxy could initialize. Eagerly fetch r.person and r.relatedPerson in the two queries used by these endpoints, keeping the no-@Transactional convention for read methods. Co-Authored-By: Claude Opus 4.7 --- .../relationship/PersonRelationshipRepository.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/org/raddatz/familienarchiv/relationship/PersonRelationshipRepository.java b/backend/src/main/java/org/raddatz/familienarchiv/relationship/PersonRelationshipRepository.java index 14a70fd3..4f204505 100644 --- a/backend/src/main/java/org/raddatz/familienarchiv/relationship/PersonRelationshipRepository.java +++ b/backend/src/main/java/org/raddatz/familienarchiv/relationship/PersonRelationshipRepository.java @@ -16,7 +16,11 @@ public interface PersonRelationshipRepository extends JpaRepository findAllByRelationTypeIn(Collection types); + @Query("SELECT r FROM PersonRelationship r " + + "JOIN FETCH r.person " + + "JOIN FETCH r.relatedPerson " + + "WHERE r.relationType IN :types") + List findAllByRelationTypeIn(@Param("types") Collection types); /** Used for the circular-PARENT_OF check in {@code addRelationship}. */ boolean existsByPersonIdAndRelatedPersonIdAndRelationType( @@ -38,6 +42,8 @@ public interface PersonRelationshipRepository extends JpaRepository findAllByPersonIdOrRelatedPersonId(@Param("personId") UUID personId); }