Project

General

Profile

« Previous | Next » 

Revision cb34fef4

Added by Andreas Kohlbecker almost 6 years ago

ref #7377 modifying test to avoid autoflush

View differences:

cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/initializer/AdvancedBeanInitializerTest.java
25 25

  
26 26
import org.apache.log4j.Level;
27 27
import org.apache.log4j.Logger;
28
import org.hibernate.FlushMode;
28 29
import org.hibernate.Hibernate;
29 30
import org.hibernate.HibernateException;
30 31
import org.hibernate.SessionFactory;
......
264 265
        assertTrue(Hibernate.isInitialized(taxon.getName()));
265 266
        TaxonName name = taxon.getName();
266 267
        // the TitleAndNameCacheAutoInitializer must not intitialize the nomenclaturalReference
267
        // since the authorship is nonly taken from the combinationAutors field
268
        // since the authorship is only taken from the combinationAutors field
268 269
        assertFalse(Hibernate.isInitialized(name.getNomenclaturalReference()));
269 270
    }
270 271

  
......
278 279

  
279 280
        deacivatedAutoIntitializers = clearAutoinitializers();
280 281
        // load bean with autoinitializers deactivated
282
        factory.getCurrentSession().setFlushMode(FlushMode.MANUAL); // TODO this is only needed due to #7377 and should be removed otherwise
281 283
        Taxon taxon = (Taxon)taxonDao.load(taxonUuid, Arrays.asList("name.nomenclaturalReference.authorship"));
282
        assertTrue(Hibernate.isInitialized(taxon.getName()));
284
        assertTrue(Hibernate.isInitialized(taxon.getName())); // name
283 285
        TaxonName name = taxon.getName();
284
        assertTrue(Hibernate.isInitialized(name.getNomenclaturalReference()));
285
        assertTrue(Hibernate.isInitialized(name.getNomenclaturalReference().getAuthorship()));
286
        assertTrue(Hibernate.isInitialized(name.getNomenclaturalReference())); // nomenclaturalReference
287
        assertTrue(Hibernate.isInitialized(name.getNomenclaturalReference().getAuthorship())); // authorship
286 288
        Team team = HibernateProxyHelper.deproxy(name.getNomenclaturalReference().getAuthorship(), Team.class);
287 289

  
288
        // FIXME: the below assertion fails, this is not citical but an inconsistency
289
        // members should not intitialized since they where not included in the property path
290
        // assertFalse("members should not intitialized since they where not included in the property path", Hibernate.isInitialized(team.getTeamMembers()));
290
        // FIXME : the below assertion fail due to #7377 if the session flushmode is AUTO, this is not critical but an inconsistency.
291
        //    In AdvancedBeanInitializer.bulkLoadLazyBeans(BeanInitNode node) the query.list()
292
        //    with "QueryImpl( SELECT c FROM TeamOrPersonBase as c  WHERE c.id IN (:idSet) )" triggers an autoFlush.
293
        //    In turn of the autoflush the team.titleCache is generated which causes the teamMembers to be initialized
294
        //
295
        // members should not initialized since they where not included in the property path
296
        assertFalse("members should not intitialized since they where not included in the property path", Hibernate.isInitialized(team.getTeamMembers()));
291 297

  
292 298
        // activate the teamAutoInitializer again
293 299
        AutoPropertyInitializer<CdmBase> teamAutoInitializer = deacivatedAutoIntitializers.get(Team.class);
294 300
        deacivatedAutoIntitializers.remove(teamAutoInitializer);
295 301
        defaultBeanInitializer.getBeanAutoInitializers().put(Team.class, teamAutoInitializer);
296 302

  
297
        taxon = (Taxon)taxonDao.load(taxonUuid, Arrays.asList("$"));
303
        taxon = (Taxon)taxonDao.load(taxonUuid, Arrays.asList("name.nomenclaturalReference.authorship"));
298 304

  
299 305
        team = HibernateProxyHelper.deproxy(name.getNomenclaturalReference().getAuthorship(), Team.class);
300 306
        assertTrue("members should have been intitialized by the ", Hibernate.isInitialized(team.getTeamMembers()));

Also available in: Unified diff