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 <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,11 @@ public interface PersonRelationshipRepository extends JpaRepository<PersonRelati
|
|||||||
* Bulk fetch for the network endpoint — pulls only edges of the given types.
|
* Bulk fetch for the network endpoint — pulls only edges of the given types.
|
||||||
* The service filters by family_member afterwards.
|
* The service filters by family_member afterwards.
|
||||||
*/
|
*/
|
||||||
List<PersonRelationship> findAllByRelationTypeIn(Collection<RelationType> types);
|
@Query("SELECT r FROM PersonRelationship r " +
|
||||||
|
"JOIN FETCH r.person " +
|
||||||
|
"JOIN FETCH r.relatedPerson " +
|
||||||
|
"WHERE r.relationType IN :types")
|
||||||
|
List<PersonRelationship> findAllByRelationTypeIn(@Param("types") Collection<RelationType> types);
|
||||||
|
|
||||||
/** Used for the circular-PARENT_OF check in {@code addRelationship}. */
|
/** Used for the circular-PARENT_OF check in {@code addRelationship}. */
|
||||||
boolean existsByPersonIdAndRelatedPersonIdAndRelationType(
|
boolean existsByPersonIdAndRelatedPersonIdAndRelationType(
|
||||||
@@ -38,6 +42,8 @@ public interface PersonRelationshipRepository extends JpaRepository<PersonRelati
|
|||||||
* Used by the "direct relationships" listings (person edit, side panel).
|
* Used by the "direct relationships" listings (person edit, side panel).
|
||||||
*/
|
*/
|
||||||
@Query("SELECT r FROM PersonRelationship r " +
|
@Query("SELECT r FROM PersonRelationship r " +
|
||||||
|
"JOIN FETCH r.person " +
|
||||||
|
"JOIN FETCH r.relatedPerson " +
|
||||||
"WHERE r.person.id = :personId OR r.relatedPerson.id = :personId")
|
"WHERE r.person.id = :personId OR r.relatedPerson.id = :personId")
|
||||||
List<PersonRelationship> findAllByPersonIdOrRelatedPersonId(@Param("personId") UUID personId);
|
List<PersonRelationship> findAllByPersonIdOrRelatedPersonId(@Param("personId") UUID personId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user