Cannot get unfetched attribute from detached object, but the attribute is in the Fetch Plan

Jmix version: 2.8.1
Jmix Studio plugin version: 2.8.1-261

IntelliJ IDEA 2026.1.2
Build #IU-261.24374.151, built on May 14, 2026
Source revision: fa0cfa150836c
Runtime version: 25.0.2+10-b329.117 x86_64137.0.17-261-b81
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
Operating System: macOS 26.4.1 (25E253)
Exception reporter ID: 130125217606a47-a271-49c2-abca-7694492439bf
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Metal Rendering is ON
Kotlin: 261.24374.151-IJ
File System: Case-Sensitive Journaled HFS+ (APFS)
Browser: Safari - Version 26.4 (21624.1.16.11.4)
Database: PostgreSQL 13

Hello Everyone

For your information, I am receiving a “Cannot get unfetched attribute from detached object” exception even though my “Contact” entity and all of its attributes, ASSOCIATIONS, COMPOSITIONS, and their attributes are included in the Fetch Plan.

This occurs within the dialogWindows.detail().build() method of an open “Performance” entity detail view before the dialogWindows’ open() method is called to display the “Contact” entity in its own dialog. The exception is thrown because the gigType COMPOSITION of the Performance ASSOCIATION attribute of the “Contact” entity is not available (= null). But it is non-null when calling the build() method. It is actually displayed in the “Performance” entity’s open detail view before calling build(). The “Contact” entity itself is NEW and created in the createContact() function just before the build() method is called…

contact = metadata.create(Contact.class);
contact.setReason(informationTextArea.getValue());
contact.setSearch(perfSearch);
contact.setSearchRevision(perfSearch.getRevision());
contact.setInterest(null);
contact.setPerformance(getEditedEntity());	// Detached “Performance” entity with a non-null gigType COMPOSITION

I have extended the Contact entity _base Fetch Plan by manually adding all of the ASSOCIATION and COMPOSITION references (and set them to _base and added all of their attributes), and during my multiple attempts to resolve this problem, I have recursively added the entity (everything) many times. When I manually step into the build() method, and through the other internal code, the number of times I see the entity and the gigType COMPOSITION attribute is increased after having added the recursive references, but at some point I still receive the exception.

I see the gigType COMPOSITION multiple times when it passes through this getValue() method (EntityValues.java line 100) and its value is non-null for almost all of these calls until at some point it is null and the exception is thrown.

public static  T getValue(Object entity, String name) {
return getEntityEntry(entity).getAttributeValue(name);
}

When I say “almost all of these calls”, I mean that I have seen a gigType = null value, that did not throw an exception, as well as a Performance = null value, that did not throw an exception, but these attributes had non-null values during the next iterations while stepping, and I stepped through this method, and saw a non-null gigType values at least 20 times over a 50 minute period, while recursively traversing my latest Fetch Plan a few days ago. Here you see some examples that prove that the gigType value is available (non-null) when entering the build() method and during the majority of the calls to EntityValues.java’s getValue() method (above).

Here is a null value for the gigType COMPOSITION without an exception

Here is a null value for the Performance ASSOCIATION without an exception

Furthermore, I set a breakpoint at setGigType() in its Performance entity’s class and it is never called; therefore, gigType is not overwritten within the build() method.

Here is the example of another attempt (different Performance entity ID), where you see the non-null value in the getValue() method, but the next time it is called the value is null, and the exception occurs.

An now the exception is thrown…

I have also tried to find the source of the problem by disabling lazy loading with jmix.eclipselink.disable-lazy-loading = true but I was unsuccessful. I have also tried to use fetch=“JOIN” instead of the AUTO setting in the Fetch Plan without any resolution. I have set other breakpoints, but much of the code is very abstract and sparsely documented, so was not yet able to determine where gigType is set to null.

My entity structure is very complex, so I am certain that I cannot provide a demo project to show how to reproduce this; therefore, I need some specific advice about what else I need to look for and where. I can single step through the code for weeks, but a few suggestions would certainly help. I am convinced that this is a bug; the gigType ASSOCIATION is non-null when the detached Performance entity enters the build() method, and if it is physically fetched again, then the gigType ASSOCIATION and its attributes should also be fetched.

Furthermore, it would be helpful to have detailed fetch plan examples for entities with nested ASSOCIATIONS and COMPOSITIONS, e.g. Many-to-Many relationship, so that it is explicilty clear when to stop the fetch plan recursion; it should be obvious, but it is not when this type of problem occurs.

Thank you in advance for your feedback and support.

Best regards
Chris

Hi Chris,

A few questions:

  1. Did it work on a previous Jmix version, or is it new code that you wrote in 2.8.1?

  2. You are creating a new instance of Contact and setting a previously loaded Performance instance into it. The question is, what fetch plan have you used when loading that Perfomance. Does it include gigType collection?

Regards,
Konstantin

@krivopustov

Hi Konstantin

Thank you for your quick response.

  1. I had a similar problem in the past with v2.3, 2.4 and v2.5 with a different attribute and in a different view. At that time I was using a different Fetch Plan, but I had specifically included the attribute that was throwing the exception then too, without success. At that time I was still migrating many of my screens, so I changed my Fetch Plan to _base everywhere and also manually included the remaining attributes, so that I could continue with my work, thinking that I would debug it later. I do not remember having this problem in v2.7 but I may not have tested this particular view. In the meantime with v2.8.x I refactored some other code in a completely different area and began testing again, and this is when this problem occurred. This code is not new for v2.8.x.; I believe that I wrote it in v.2.4, but would need to check my commits to be sure.
  2. Yes, I am creating a new Contact instance and then setting the previously loaded Performance instance (from the currently open view) into it. The Performance entity Fetch Plan is also _base and I had added all of its other ASSOCIATION and COMPOSITION attributes manually and recursively, including gigType. In the meantime, I have been fetching everything for all of my entities to try and avoid this particular problem, and this is why I do not understand why this is happening.

The images in my original post above of gigType going through the getValue() method show a subset of the calls; I watched it go through many more times with a non-null value. The exception is thrown regardless of whether the gigType COMPOSITION is empty or contains an instance; In my first image above it contains an instance. I have verified this several times, also while stopping and recompiling everything.

Looking through my screens shots more closely, I see that the coverTypes attribute’s value changes back and forth from 1 to 0 and back to 1 several times. This should also not occur. There is no internal code to modify this attribute, and the trace is still inside the build()method; coverTypes is only entered by the user with a radio button. This is very strange.

Do you have any recommendations?

Best regards

Chris

The error occurs during merging your object graph into DataContext of the Contact detail view. This is a complicated procedure and it can fail on complex graphs with cyclic references or usage of the same entity in different places with different fetch plans.

Please provide the following information:

  • Full stack trace of the error
  • Code of related entities, what references are empty in the database
  • Fetch plans used to load Performance and Contact

We’ll try to reproduce the problem.

@krivopustov

Hi Konstantin

Thank you for the information and your support.

I have put together the information that you requested, at least my understanding of what you might initially need for your analysis. Furthermore, I manually edited my fetchPlans.xml to ensure that I am not including any nested/recursive entity references, and I can still reproduce the problem every time.

In the attached file StackTrace-Code-FetchPlans.01.zip (21.7 KB) you will find the current stack trace, some entity definitions, view data and facets definitions, the relevant fetch plans, and database dumps (.csv files). As noted below, the Performance entity is a sub-class of Interest.

Here is a short overview of the entities and their COMPOSITIONs that are involved…

Entity, DB Empty, Description

Interest, No, Entity (multiple instances per user)
ambition, Yes, COMPOSITION
availability, Yes, COMPOSITION
instrument_profiles, No, COMPOSITION for a Many-to-Many

Performance, No, Entity (multiple instances per user) - [sub-class of interest]
covers, Yes, COMPOSITION
gig_type, No, COMPOSITION
gig_location, Yes, COMPOSITION
gig_season, Yes, COMPOSITION
group_formation, No, COMPOSITION
music_style, No, COMPOSITION

Contact, Yes, Entity (multiple instances per user)
message, Yes, COMPOSITION

The workflow is as follows…

  1. The user selects a saved search result, which contains a reference to a Performance instance, from a list of SearchResult instances.
  2. The user opens the Performance instance in a detail view (dialogWindow).
  3. Within the Performance detail view the user decides to create a Contact instance and immediately edit it in a detail view (dialogWindow); the exception occurs here, as originally reported above.

I hope that this information is helpful. Many thanks and good luck!

Best regards
Chris

Hi Chris,
Thank you for the additional information. We will investigate the problem.

Hi Chris,
Unfortunately I couldn’t reproduce the problem in a plausible test scenario.

I suspect that the cause can be in that Performance is a subclass of Interest, and you load Interest instances in ContactDetailView, so there actually may be instances of Performance without GigType in the DataContext. Try to rewrite this part and load concrete Performance class everywhere.

You can also send me a link to your project with minimal required data in a private message. As soon as we reproduce the issue, we’ll be able to fix it in the framework.