Different behaviour with Jmix 2.7.x in reporting

Hi Everybody

Until Jmix 2.7.x the following groovy script did work

import org.biooffice.bio4.entity.TLoanItem

def result = [];

def posList = dataManager.load(TLoanItem)
                .query("e.ltmIdLoan = ?1", params['Loan'])
                .list();
                
posList.each(
    pos->{
        result.add([
            'objStorageNumber'   : pos.ltmIdObject.objStorageNumber,
            'taxTaxonDisplay'    : pos.ltmIdObject.objDetIdTaxon.taxTaxonDisplay,
            'taxTaxonCommonName' : pos.ltmIdObject.objDetIdTaxon.taxTaxonCommonName,
            'objStorageLevel4'   : pos.ltmIdObject.objStorageLevel4,
            'ltmDateInPlanned'   : pos.ltmDateInPlanned
            ])
    }
);

return result;

Since version 2.7.x I get an error

ReportingException: An error occurred while loading data for band [Data] and query [dataSet1]. Report name [Leihschein]
An error occurred while loading data for data set [dataSet1]
Cannot get unfetched attribute [objDetIdTaxon] from detached object org.biooffice.bio4.entity.TObject-26160 [detached].

There are now several solutions to resolve this.

Why did it work before 2.7.x ?

What is the best way to handle this case after 2.7.x ?

Thank you

Best regards

Felix

Hello,

I don’t know why it worked before, but
“Cannot get unfetched attribute [objDetIdTaxon] from detached object” basically says that you need to adjust your fetch plan, or query the value yourself.

Kind regards,
Mladen

Hi @mbucan

We have the same state :wink:

I know it is unfetched and I would like understand, how in Jmix 2.6 this was working !

I have a lot of reports which I have to check and to adapt. Before I now fetch everything piece by piece, I would like to know why it did work before to go to that point and adjust it on that central point.

I think, just with the import org.biooffice.bio4.entity.TLoanItem there is no fetchplan, correct ?

Kind regards
Felix

No.
I have some complex Groovy scripts that are related to BPM reporting, and I guess I was lucky because I call the BPM or Flowable api directly to get my result elements mostly.

Hi Everybody

There is the solution to have instead of

        'taxTaxonDisplay'    : pos.ltmIdObject.objDetIdTaxon.taxTaxonDisplay,
        def bioObject = dataManager.load(TObject)
                .query("e.id = ?1", pos.ltmIdObject.id)
                .one();
                
        def taxon = dataManager.load(TTaxa)
                .query("e.id = ?1", bioObject.objDetIdTaxon.id)
                .one();

        'taxTaxonDisplay'    : taxon.taxTaxonDisplay,

But, I expect this is somewhere documented; did I miss something ?

And now, another report not working anymore

io.jmix.reports.exception.ReportingException: Error formatting jasper report: Error evaluating expression for source text: $F{objPropStadium} Report name [Objekte 78x55 mm Etiketten]
Error evaluating expression for source text: $F{objPropStadium}
Cannot cast org.biooffice.bio4.entity.TlkpcsObjPropStadium to java.lang.String

So if the report is running with 2.6

'objPropStadium' : tObject.objPropStadium,

and then in Jmix 2.7

'objPropStadium' : tObject.objPropStadium.lkpcsObjPropStadiumText1,

Thes are 2 breaking changes in the addon Reporting, which are nowhere mentioned.

For helping the developers, this should be mentioned.

Regards

Felix

Hi Felix,

Looks like lazy loading doesn’t work in your case for some reason.

I cannot reproduce this on the latest 2.7, the following Groovy script works fine for me in a report:

import com.company.onboarding.entity.User

def result = []
def users = dataManager.load(User).all().list()
users.each {
    result.add(
        [
            'username': it.username, 
            'companyName': it.department?.company?.name
        ]
    )
}
return result

Could you provide a test project?

Regards,
Konstantin

Hi @krivopustov

Yesterday I did spend hours trying to reproduce this problem.

My originalapplication has 116 entities …

I did now extract a testproject with 5 relevant entities, which is working in 2.6 and 2.7. So I will have to search, where is the difference between these 116 entities and the 5 entities.

I did isolate one problem where I would be happy to get an explanation. The excrypt is from the t-loan-item-detail-view.xml from the attached project.

In the entity TLoanItem all fields have the prefix ltm. In the attaced project with 5 entities, these fields have to be mentioned in the fetchplan.

{8B93042C-11E0-4867-AB37-32BBAD7F0557}

In my application with 116 entities, these fields do not have to be mentioned ( which I understand )

{B517DA42-2BEC-4E48-A0B4-B71149B0083C}

I understand, _base fetch plan includes all attributes of the _local and _instance_name fetch plans, plus embedded references.

How to find out, why in the attached testproject, these properties have to be explicitly mentioned ?

Best regards
Felix

Report26.zip (161.1 KB)
In this project the report from TLoan is included and working (which is not the case in the 116 entity project).

The attached project is correct: ltmIdLoan is a reference attribute and must be explicitly included in the fetch plan, because _base fetch plan doesn’t include it.

The question is why in your 116-entities project the Studio suggest the opposite. Are you sure the data model is the same?

I wonder, that with _baseembedded references should be loaded too ?
ltmIdLoan is a direct association to Loan where LoanItem is a composition.

How to debug, what is really loaded ?

Both projects have the same datamodel, limited to the contained entities

{9A943D7E-18FA-4624-BC12-56F14CD111DB}

As you see, there are from TLoan more references to TContact, which I think is not relevant.

A funny observation is, that if in the big project I exclude the objDetIdTaxon as sugggested by the Studio, Studio is complaining, that it should be included in the case of the String taxTaxonCommonName, but for the same case String taxTaxonDisplay, it does not complain ;/

{D5178A58-6DBA-4669-AD94-454542640768}

As I said, would be great to be able to debug, why and what is really loaded ( this would be great for optimisation too, as this might be an issue for the speed of the application)

If it helps, I can privatly share with you the 116-entities project.

Thank you for your help

Best regards

Felix

Actually all details of the entities in question matter, including multiple references to the same entity.
Please either make the test project model identical, or share the real project (e.g. send me a link in a private message).

Set these logger levels to see database operations and fetching configuration:

logging.level.io.jmix.core.datastore=debug
logging.level.eclipselink.logging.sql=debug
logging.level.io.jmix.eclipselink.impl.FetchGroupManager=trace

Also, you can use EntityStates.isLoaded(entity, propertyName) method to test in your code whether an entity attribute is loaded.

Regards,
Konstantin