Project

General

Profile

Actions

bug #7331

open

AdvancedBeanInitializer fails to initialize properties of preinitialized beans in the graph in very special situations

Added by Andreas Kohlbecker almost 6 years ago. Updated over 3 years ago.

Status:
New
Priority:
New
Category:
cdmlib
Target version:
Start date:
Due date:
% Done:

10%

Estimated time:
Severity:
normal
Found in Version:
Tags:

Description

In the RegistrationWorkingSetService.loadWorkingSetByReferenceID(Integer referenceID) a RegistrationWorkingSet is loaded with the following code:


List<String> REGISTRATION_INIT_STRATEGY = Arrays.asList(new String []{
            "blockedBy",
            // typeDesignation
            "typeDesignations.typeStatus",
            "typeDesignations.typifiedNames.typeDesignations", // important !!
            "typeDesignations.typeSpecimen",
            "typeDesignations.typeName.$",
            "typeDesignations.citation",
            "typeDesignations.citation.authorship.$",
            // name
            "name.$",
            "name.nomenclaturalReference.authorship.$",
            "name.nomenclaturalReference.inReference",
            "name.rank",
            "name.homotypicalGroup.typifiedNames",
            "name.status.type",
            "name.typeDesignations", // important !!"
            // institution
            "institution",
            }
    );

Reference reference = repo.getReferenceService().find(referenceID);
Pager<Registration> pager = repo.getRegistrationService().page(Optional.of(reference), null, null, null, REGISTRATION_INIT_STRATEGY);
return new RegistrationWorkingSet(makeDTOs(pager.getRecords()));

This usually works, but with a specific data set the pager contains Registrations where authorship
properties of the nomenclaturalReferences are not initialized even if the AdvancedBeanInitializer apparently is doing the initialization properly (also confirmed by debugging):

[eu.et.cd.pe.da.in.AdvancedBeanInitializer] -  processing /name.nomenclaturalReference
[eu.et.cd.pe.da.in.AdvancedBeanInitializer] -  invoke initialization on /name.nomenclaturalReference beans of class TaxonName ... 
[eu.et.cd.pe.da.in.AdvancedBeanInitializer] - bulk load /name.nomenclaturalReference
[eu.et.cd.pe.da.in.AdvancedBeanInitializer] - bulk load /name.nomenclaturalReference - DONE 
[eu.et.cd.pe.da.in.AdvancedBeanInitializer] -  processing /name.nomenclaturalReference.authorship
[eu.et.cd.pe.da.in.AdvancedBeanInitializer] -  invoke initialization on /name.nomenclaturalReference.authorship beans of class Reference ... 
[eu.et.cd.pe.da.in.AdvancedBeanInitializer] - bulk load /name.nomenclaturalReference.authorship
[eu.et.cd.pe.da.in.AdvancedBeanInitializer] - bulk load beans of class TeamOrPersonBase
[eu.et.cd.pe.da.in.AdvancedBeanInitializer] -  SELECT c FROM TeamOrPersonBase as c  WHERE c.id IN (:idSet) 
[eu.et.cd.pe.da.in.AdvancedBeanInitializer] - initialize bulk loaded beans of class TeamOrPersonBase: [1383]
[eu.et.cd.pe.da.in.AdvancedBeanInitializer] - bulk load - DONE

The actual initialization takes place in AdvancedBeanInitializer.bulkLoadLazyBeans(BeanInitNode node). Here a strange behavior can be observed in these special cases:


private void bulkLoadLazyBeans(node node) {
        for (Class<?> clazz : node.getLazyBeans().keySet()){
            Set<Serializable> idSet = node.getLazyBeans().get(clazz);
    String hql = " SELECT c FROM %s as c %s WHERE c.id IN (:idSet) ";
    hql = String.format(hql, clazz.getSimpleName(), autoInit.leftJoinFetch); // hql = "SELECT c FROM TeamOrPersonBase as c  WHERE c.id IN (:idSet)" 
    Query query = genericDao.getHqlQuery(hql);
    query.setParameterList("idSet", idSet);
    List<Object> list = query.list();

Now the TeamOrPersonBase entities are initialized.
However, checking the parent object contained in the node object passed as parameer reveals that the 'authorship' proxy in the object graph has not been initialized.

Preloading the reference in the RegistrationWorkingSetService.loadWorkingSetByReferenceID(Integer referenceID) method avoids the problem (in the below code only relevant lines are shown)


Reference reference = repo.getReferenceService().find(referenceID);
repo.getReferenceService().load(reference.getUuid());

Since this behavior is data dependent, I serialized the fully initialized registrations as loaded in the RegistrationDaoHibernateImpl.list(Optional<Reference> reference, Collection<RegistrationStatus> includedStatus, Integer limit, Integer start, List<String> propertyPaths). registrations-fully-initialized.ser can be used to restore the original data by de-serializing and persisting the objects to a cdm-database (version 4.15.0-SNAPSHOT) :


 try {
            FileInputStream fin = new FileInputStream("registrations-fully-initialized.ser");
            ObjectInputStream oin = new ObjectInputStream(fin);
            List<Registration> registrationsDeserialized = (List<Registration>) oin.readObject();
        } catch (ClassNotFoundException | IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

NOTE: Doing the serialization in RegistrationDaoHibernateImpl.list() also removed the problem described in here:


        try {
            FileOutputStream fout = new FileOutputStream("registrations-before-initialization.ser");
            ObjectOutputStream oos = new ObjectOutputStream(fout);
            oos.writeObject(results);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        defaultBeanInitializer.initializeAll(results, propertyPaths);

        // initialization is incomplete

        try {
            FileOutputStream fout = new FileOutputStream("registrations-after-initialization.ser");
            ObjectOutputStream oos = new ObjectOutputStream(fout);
            oos.writeObject(results);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // fully initialized now! the file registrations-fully-initialized.ser has been created after this 


Additional tasks:

Potentially duplicate tickets:



Files


Related issues

Related to EDIT - bug #7342: incomplete bean initialization with specific data causes LIEsWorksformeAndreas Kohlbecker

Actions
Related to EDIT - task #7330: TitleAndNameCacheAutoInitializer misses out ReferencesNewAndreas Müller

Actions
Has duplicate EDIT - bug #7511: LazyInitializationException (LIE) opening Registration Workingset EditorDuplicateAndreas Kohlbecker

Actions
Actions #1

Updated by Andreas Kohlbecker almost 6 years ago

  • Description updated (diff)
Actions #2

Updated by Andreas Kohlbecker almost 6 years ago

  • File registrations-after-incomplete-initialization.ser added
  • File registrations-before-initialization.ser added
Actions #3

Updated by Andreas Kohlbecker almost 6 years ago

  • Description updated (diff)
  • Found in Version set to Release 5.0
Actions #4

Updated by Andreas Kohlbecker almost 6 years ago

  • Description updated (diff)
Actions #5

Updated by Andreas Kohlbecker almost 6 years ago

  • File deleted (registrations-before-initialization.ser)
Actions #6

Updated by Andreas Kohlbecker almost 6 years ago

  • File deleted (registrations-after-incomplete-initialization.ser)
Actions #7

Updated by Andreas Kohlbecker almost 6 years ago

  • File registrations-fully-initialized.ser added
Actions #8

Updated by Andreas Kohlbecker almost 6 years ago

  • Description updated (diff)
Actions #9

Updated by Andreas Kohlbecker almost 6 years ago

  • Description updated (diff)
Actions #10

Updated by Andreas Kohlbecker almost 6 years ago

  • Description updated (diff)
Actions #11

Updated by Andreas Kohlbecker almost 6 years ago

  • File deleted (registrations-fully-initialized.ser)
Actions #13

Updated by Andreas Kohlbecker almost 6 years ago

  • % Done changed from 0 to 10
Actions #14

Updated by Andreas Kohlbecker almost 6 years ago

I created a test to reproduce this problem in isolation 7d60d703 without success and I am avoiding the effect of this bug in RegistrationWorkingSetService.loadWorkingSetByReferenceID() by doing an explicit load of the Reference commit:cdm-vaadin|7d60d70.

And now I am leaving this issue in favor of getting some other work done ...

Actions #15

Updated by Katja Luther almost 6 years ago

  • Related to bug #7342: incomplete bean initialization with specific data causes LIEs added
Actions #16

Updated by Andreas Kohlbecker almost 6 years ago

  • Description updated (diff)
Actions #17

Updated by Andreas Kohlbecker over 5 years ago

  • Has duplicate bug #7511: LazyInitializationException (LIE) opening Registration Workingset Editor added
Actions #18

Updated by Andreas Kohlbecker over 5 years ago

Adding exported breakpoints from my eclipse which might help debugging this issue.

Actions #19

Updated by Andreas Kohlbecker over 3 years ago

  • Related to task #7330: TitleAndNameCacheAutoInitializer misses out References added
Actions #20

Updated by Andreas Kohlbecker over 3 years ago

  • Description updated (diff)
Actions #21

Updated by Andreas Kohlbecker over 3 years ago

  • Description updated (diff)
Actions #22

Updated by Andreas Kohlbecker over 3 years ago

  • Related to bug #9095: LazyInitializationException (LIE) in portal/description/distributionInfoFor/{uuid} added
Actions #23

Updated by Andreas Kohlbecker over 3 years ago

  • Related to bug #9096: LazyInitializationException (LIE) in DescriptionElementListController.getDescriptionElementsForTaxon() added
Actions #24

Updated by Andreas Müller over 3 years ago

  • Description updated (diff)
Actions #25

Updated by Andreas Kohlbecker over 3 years ago

  • Related to deleted (bug #9095: LazyInitializationException (LIE) in portal/description/distributionInfoFor/{uuid})
Actions #26

Updated by Andreas Kohlbecker over 3 years ago

  • Related to deleted (bug #9096: LazyInitializationException (LIE) in DescriptionElementListController.getDescriptionElementsForTaxon())
Actions

Also available in: Atom PDF