chore(document): address non-blocking review feedback on lazy-fetch PR
All checks were successful
CI / Unit & Component Tests (push) Successful in 3m11s
CI / OCR Service Tests (push) Successful in 20s
CI / Backend Unit Tests (push) Successful in 3m41s
CI / fail2ban Regex (push) Successful in 44s
CI / Semgrep Security Scan (push) Successful in 19s
CI / Compose Bucket Idempotency (push) Successful in 1m0s
All checks were successful
CI / Unit & Component Tests (push) Successful in 3m11s
CI / OCR Service Tests (push) Successful in 20s
CI / Backend Unit Tests (push) Successful in 3m41s
CI / fail2ban Regex (push) Successful in 44s
CI / Semgrep Security Scan (push) Successful in 19s
CI / Compose Bucket Idempotency (push) Successful in 1m0s
- Add @BatchSize(50) fallback comments on findBySenderId / findByReceiversId - Replace silent size() discard in getRecentActivity test with assertThat isNotEmpty() - Add ADR-022 reference comment above @JsonIgnoreProperties on Person and Tag - Document within-open-transaction limitation in DocumentLazyLoadingTest Javadoc Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit was merged in pull request #622.
This commit is contained in:
@@ -50,9 +50,11 @@ public interface DocumentRepository extends JpaRepository<Document, UUID>, JpaSp
|
|||||||
// Prüft effizient, ob ein Dateiname schon existiert (gibt true/false zurück)
|
// Prüft effizient, ob ein Dateiname schon existiert (gibt true/false zurück)
|
||||||
boolean existsByOriginalFilename(String originalFilename);
|
boolean existsByOriginalFilename(String originalFilename);
|
||||||
|
|
||||||
|
// lazy – @BatchSize(50) fallback active; see ADR-022
|
||||||
@EntityGraph("Document.full")
|
@EntityGraph("Document.full")
|
||||||
List<Document> findBySenderId(UUID senderId);
|
List<Document> findBySenderId(UUID senderId);
|
||||||
|
|
||||||
|
// lazy – @BatchSize(50) fallback active; see ADR-022
|
||||||
@EntityGraph("Document.full")
|
@EntityGraph("Document.full")
|
||||||
List<Document> findByReceiversId(UUID receiverId);
|
List<Document> findByReceiversId(UUID receiverId);
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
// prevents infinite recursion in JSON serialization; see ADR-022 for lazy-fetch context
|
||||||
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
|
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "persons")
|
@Table(name = "persons")
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
|
// prevents infinite recursion in JSON serialization; see ADR-022 for lazy-fetch context
|
||||||
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
|
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
|
||||||
@Entity
|
@Entity
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
@@ -28,6 +28,17 @@ import static org.assertj.core.api.Assertions.assertThatCode;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies that lazy-loaded associations on {@link Document} are accessible after a service
|
||||||
|
* method returns — i.e. no {@link org.hibernate.LazyInitializationException} is thrown outside
|
||||||
|
* the Hibernate session that loaded the entity.
|
||||||
|
*
|
||||||
|
* <p><b>Known limitation:</b> calling {@code getDocumentById} (or any other service method) from
|
||||||
|
* within an already-open transaction is not covered here. When an outer transaction is active,
|
||||||
|
* the service's own {@code @Transactional} merges into it and Hibernate keeps the same session
|
||||||
|
* open, so the lazy-init guard behaves differently than in a non-transactional caller. This is a
|
||||||
|
* known constraint of the test setup, not a bug in the production code.
|
||||||
|
*/
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||||
@ActiveProfiles("test")
|
@ActiveProfiles("test")
|
||||||
@Import(PostgresContainerConfig.class)
|
@Import(PostgresContainerConfig.class)
|
||||||
@@ -100,6 +111,7 @@ class DocumentLazyLoadingTest {
|
|||||||
}).doesNotThrowAnyException();
|
}).doesNotThrowAnyException();
|
||||||
results.forEach(d -> assertThat(d.getSender()).isNotNull());
|
results.forEach(d -> assertThat(d.getSender()).isNotNull());
|
||||||
results.forEach(d -> assertThat(d.getSender().getLastName()).isNotNull());
|
results.forEach(d -> assertThat(d.getSender().getLastName()).isNotNull());
|
||||||
|
results.forEach(d -> assertThat(d.getTags()).isNotEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user