Skip to content

feat: Add NoEagerToOneAssociationRule as a standalone rule - #165

Merged
MilczekT1 merged 1 commit into
mainfrom
worktree-no-eager-to-one-association
Oct 25, 2026
Merged

MilczekT1 merged 1 commit into
mainfrom
worktree-no-eager-to-one-association

Conversation

@MilczekT1

Copy link
Copy Markdown
Owner

Closes #61.

Summary

  • Adds corral.jakarta.no-eager-to-one-association, a standalone rule (in no group). Consumers wire it with ArchTests.in(NoEagerToOneAssociationRule.class).
  • What it flags: every field or getter annotated @ManyToOne / @OneToOne, Jakarta or javax Persistence, that is either:
    • missing fetch = LAZY (the spec default for a to-one is EAGER), or
    • carrying Hibernate's @Fetch(FetchMode.JOIN), which loads it eagerly whatever fetch says.
  • Violation line: one per member, in one fixed shape: Field <…> is a to-one association that may be fetched eagerly in (File.java:N).
    • The wording stays true on Jakarta Persistence 4.0, where an unset fetch is FetchType.DEFAULT and follows the persistence unit's setting.
    • The line never prints the resolved fetch value, which differs by API version and classpath.
  • Matched by annotation name, so the rule loads without a Persistence API or Hibernate on the classpath. When the annotation type doesn't resolve, a missing fetch still counts as eager. It checks production and test classes.
  • Not checked, and stated in the RuleDoc and the docs row:
    • orm.xml mappings;
    • Hibernate's @Any, @LazyToOne and @NotFound;
    • Jakarta Persistence 4.0's @jakarta.persistence.Fetch (not final yet, so there is no real type to build a fixture from);
    • a LAZY to-one that Hibernate loads immediately anyway: the inverse side of an optional @OneToOne, or a target entity it cannot proxy.
  • Wiring: a committed freeze store and its stored.rules line, a field on EveryStandaloneRule, and a row in the Standalone table of docs/rules.md.

Test plan

  • ./mvnw clean verify: green, coverage gates met.
  • Fixtures:
    • 8 must-flag and 7 must-ignore members across a Jakarta entity, a javax entity and a property-access entity, all built from real jakarta.persistence-api, javax.persistence-api and hibernate-core types;
    • one test for the case where the annotation type doesn't resolve.
  • Clause-by-clause mutation testing: 14 mutations, covering each subject annotation, each entry of the lazy-check list, both causes, the LAZY/JOIN filters, the @Fetch name and the handling of an absent fetch. A named test failed for every one.
  • The committed store survives unrelated edits to the examples without reseeding.
  • rule-reviewer run. Its findings are fixed: the wording now holds on JPA 4.0, the 4.0 @Fetch gap is documented, the warning about targets that can't be proxied is in How to fix, and the exact-line assertion for the unresolved type is added.

🤖 Generated with Claude Code

Flags every field or getter annotated @manytoone or @OnetoOne, Jakarta or
javax Persistence, whose fetch is not LAZY or that carries Hibernate's
@fetch(FetchMode.JOIN). Closes #61.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 589d87fc-28ac-41da-b80d-d7d3f85edb70
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

@MilczekT1
MilczekT1 merged commit 3c07120 into main Oct 25, 2026
4 checks passed
@MilczekT1
MilczekT1 deleted the worktree-no-eager-to-one-association branch October 25, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rule proposal: corral.jakarta.no-eager-to-one-association

1 participant