Skip to content

Test for GetchGroup#3786

Open
nedge wants to merge 4 commits into
ebean-orm:masterfrom
nedge:master
Open

Test for GetchGroup#3786
nedge wants to merge 4 commits into
ebean-orm:masterfrom
nedge:master

Conversation

@nedge

@nedge nedge commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

I'm trying to force the loading of OneToMany using FetchGroups in a query....setUnmodifiable(true)
My goal is to be able to load parts of the object graph and use the ImmutableBeanCache functionality but I get

ResourceEntityTest.a_find_fetchQuerySecondary_inheritsImmutableCache_expect_noLabelLazyLoadSql:662->lambda$a_find_fetchQuerySecondary_inheritsImmutableCache_expect_noLabelLazyLoadSql$19:663 » LazyInitialisation Property not loaded: name

@rob-bygrave

Copy link
Copy Markdown
Contributor

Maybe:

Verdict: not an ebean bug — usage error. Reproduced the failure (LazyInitialisationException: Property not loaded: name). Root cause: the new test fetches fetchQuery("attributeValues", "intValue") but then accesses AttributeValue.name (a newly added @manytoone Label) which is never fetched; combined with setUnmodifiable(true) (read-only beans → lazy loading disabled by design), accessing the unfetched property correctly throws.

Confirmed fix: changing to fetchQuery("attributeValues", "intValue, name") makes the test pass including assertThat(sql).isEmpty() — the Label graph resolves entirely from the ImmutableBeanCache with zero lazy-load SQL, which is exactly the author's goal.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the resource test model and test coverage to reproduce/validate immutable-cache + FetchGroup behavior when loading deeper parts of the object graph (specifically AttributeValue -> Label -> labelTexts) and adds a Spring module load/update scenario.

Changes:

  • Add a name (Label) association to AttributeValue, including constructor/getter/setter updates.
  • Extend ResourceEntityTest setup data and add a new test that accesses AttributeValue.name.labelTexts while using an immutable Label cache and setUnmodifiable(true).
  • Add a new (currently non-annotated) testLoad() method in EbeanSpringModuleTest.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
ebean-test/src/test/java/org/tests/resource/ResourceEntityTest.java Adds AttributeValue label setup, a new immutable-cache/fetchGroup test, and a cache helper that loads labelTexts.
ebean-test/src/test/java/org/tests/resource/AttributeValue.java Introduces Label name ManyToOne association and updates constructors/accessors accordingly.
ebean-spring-txn/src/test/java/org/example/EbeanSpringModuleTest.java Adds a new load/update test scenario for User.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ebean-test/src/test/java/org/tests/resource/ResourceEntityTest.java
Comment on lines +72 to +76
av1.getName().addLabelText(de, "AV1 DE");
av1.getName().addLabelText(en, "AV1 EN");
AttributeValue av2 = new AttributeValue(new Label(), 2, widthDescriptor);
av2.getName().addLabelText(de, "AV2 DE");
av2.getName().addLabelText(en, "AV2 EN");
logger.info("nonTransactional find user1:{} user2:{}", user, user2);
}

public void testLoad() {

found = DB.find(User.class, user.getOid());

assertThat(user.getName()).equals(found.getName());
@nedge

nedge commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

I changed the code in the test case as follows (line 678)
AttributeValueOwner owner = DB.find(AttributeValueOwner.class) .setId(resource.getAttributeValueOwner().id()) .fetchLazy("attributeValues", "intValue, name") .fetch("attributeValues.attributeDescriptor", "name,description") .using(cache) .findOne();

but still getting
ResourceEntityTest.a_find_fetchQuerySecondary_inheritsImmutableCache_expect_noLabelLazyLoadSql:662->lambda$a_find_fetchQuerySecondary_inheritsImmutableCache_expect_noLabelLazyLoadSql$19:663 » LazyInitialisation Property not loaded: name

@rob-bygrave

Copy link
Copy Markdown
Contributor

Agent says:

└ Re-reviewed PR #3786. Key new finding: the contributor (nedge) misapplied my suggested fix. They added , name to the find_fetchLazySecondary_… test (line 678 — which wasn't failing and doesn't use setUnmodifiable), but the actually-failing test a_find_fetchQuerySecondary_… (~line 646) is unchanged and still has fetchQuery("attributeValues", "intValue") with setUnmodifiable(true) — hence the same LazyInitialisationException: Property not loaded: name.

@nedge

nedge commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

I still have issues in Timerbee with the FetchGroup - One part may have to do with using inheritance so I will try to remove the inheritance first.

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.

3 participants