Unfetched attribute issue probably due to One-to-One relations

Hi there,

I’m facing a very annoying issue, which I was not able to track down, and I’m hoping that you will be able to help -as usual.
We have a few entities linked to each other the following way:

Transaction -> Individual -> LeadInfo -> LeadSource

We have a simple browser window for displaying/searching the transactions in bulk. Every Transaction has an Individual belongs to it. Every Individual has a LeadInfo record attached with a one-to-one relation, and that has various Lead related tables are linked, one of them is LeadSource.
The other day someone asked me to include the Leadsource name into the grid, so they can filter/search by that.
As usual, I went to the view and included the Lead info and the Leadsource:

image

 <view class="uk.co.wealthclub.clover.transaction.Transaction"
          extends="_local"
          name="transaction-view">
        <property name="individual"
                  view="_minimal">
            <property name="salutation"/>
            <property name="fullName"/>
            <property name="email"/>
            <property name="nino"/>
            <property name="dateOfBirth"/>
            <property name="primaryAddress1"/>
            <property name="primaryAddress2"/>
            <property name="primaryAddress3"/>
            <property name="primaryAddress4"/>
            <property name="primaryAddress5"/>
            <property name="primaryPostTown"/>
            <property name="primaryPostcode"/>
            <property name="leadInfo"
                      view="_minimal">
                <property name="leadStatus"
                          view="_minimal"/>
            </property>
        </property>

And then created the column in the grid, and tried to open it. All I got was the “Unfetched attribute access” error message:
image

I have tried extending different levels in the view, like _minimal, _base, and even nothing, and ticking all the required fields, thinking there might be an issue somewhere there, but without luck. :frowning:

Could you please help?

Cheers
Gabor

I would try to set fetch=“BATCH” on problematic individual -> leadInfo view property:

 <property name="leadInfo" view="_minimal" fetch="BATCH">

Also there is a probable mistyping in your post. In attribute tree I see “leadSource” but in view definition I see “leadStatus”?

Regards,
Alex

Gabor,
what framework version are you using?

Hi Alex,
thanks for your reply, yeah you are absolutely right, I messed it up in the end, as I was struggling and trying with so many combinations, now I’ve made sure it’s correct:
image

I have put the fetchmode on that relation to ‘BATCH’, still the same I’m afraid…

Hi Konstantin,
it’s 6. 10.4, but I have tried it with 6.8.13 too

Cheers
Gabor

This is the entity definition:

image

There can be various reasons for your problem. Maybe you have a nasty BeforeDetachEntityListener which loads unloaded fields and breaks fetch group. Maybe it’s related to joined inheritance strategy.

Ideally you should try to extract minimal set of your entities to a simple CUBA project and try to reproduce the problem there.

If you will be able to create a reproducable test case then I think CUBA team would fix the bug or at least provide a workaround.

Regards,
Alex.

Hi Alex,
thank you for the suggestion, I have recreated the structure it in the customer sample project, and that works immediately. I’ll need to keep on investigating…

Hi Both,
I think I have found it out, I had to set the corresponding FetchType to EAGER on the Entities themselves (in Individual for LeadInfo and in LeadInfo for LeadSource:

in Individual:

    @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
    @JoinColumn(name = "LEAD_INFO_ID")
    protected LeadInfo leadInfo;

and in LeadInfo:

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "LEAD_SOURCE_ID")
    protected LeadSource leadSource;

Strangely enough, the Individual reference in the Transaction table is not defined, so probably it’s LAZY:

    @NotNull
    @Lookup(type = LookupType.DROPDOWN, actions = {"lookup", "open", "clear"})
    @ManyToOne(optional = false)
    @JoinColumn(name = "INDIVIDUAL_ID")
    protected Individual individual;

Which begs the questions, why did this fix it? :open_mouth:

Just an interesting observation in Studio, browser version: if the FetchType is not set to Eager already, the dropdown for it in the Entity editor won’t appear:
When it’s set to EAGER:
image

When it’s not:
image

Cheers
Gabor

Hi Gabor,

We don’t recommend setting fetch = FetchType.EAGER and cascade annotation attributes as it contradicts with the concept of views and may lead to unexpected results.
The default in JPA for ManyToOne and OneToOne is EAGER, so we set it to LAZY when generate entity classes. Studio shows the Fetch type field only if you have set the fetch type to EAGER manually, this is intentional.

We would appreciate if you send us a project with reproducible scenario of the issue.

Regards,
Konstantin