Home > Software engineering >  Hybris entity not found when running cron job
Hybris entity not found when running cron job

Time:09-16

I try to call the method synchronizeFull of the class DefaultCatalogSynchronizationService from my code which should sync from a source catalog to target catalog.
When I use the backoffice everything works fine, but when I use my code everything goes wrong.
The cron job called by this class fails each time and I get the following error:

ERROR [hybrisHTTP2] (0000009D) [Job] Caught throwable Entity not found ( pk = 
8796096201204 name = 'de.hybris.platform.persistence.processing_Job' type code = 
'500' db table = 'jobs'): object no longer valid
de.hybris.platform.jalo.JaloSystemException: Entity not found ( pk = 8796096201204 
name = 'de.hybris.platform.persistence.processing_Job' type code = '500' db table = 
'jobs'): object no longer valid[HY--1]
at de.hybris.platform.catalog.jalo.synchronization.CatalogVersionSyncJob.configureFullVersionSync(CatalogVersionSyncJob.java:502)
at de.hybris.platform.catalog.jalo.synchronization.CatalogVersionSyncJob.performCronJob(CatalogVersionSyncJob.java:840)
at de.hybris.platform.cronjob.jalo.Job.execute(Job.java:1396)
at de.hybris.platform.cronjob.jalo.Job.performImpl(Job.java:805)
at de.hybris.platform.cronjob.jalo.Job.performImpl(Job.java:720)
at de.hybris.platform.cronjob.jalo.Job.perform(Job.java:632)
at de.hybris.platform.servicelayer.cronjob.impl.DefaultCronJobService.performCronJob(DefaultCronJobService.java:81)
at de.hybris.platform.catalog.synchronization.DefaultCatalogSynchronizationService.synchronizeFully(DefaultCatalogSynchronizationService.java:74)

any idea?

UPDATE:
Here is the code which I call in one of my classes (the CatalogSynchronizationService is a standard class of hybris)

this.catalogSynchronizationService.synchronizeFully(source, target);

UPDATE 2:
The sync seems to work fine when I remove the value of a field called Exploded drawing (which contains a picture of the product) from the product.

CodePudding user response:

use local session context to run syncjob programmatically, as below.

return getSessionService().executeInLocalView(new SessionExecutionBody()
        {
            @Override
            public Object execute()
            {
                this.catalogSynchronizationService.synchronizeFully(source, target);
           return true;
            }
        });

Or use

synchronizeFullyInBackground(final CatalogVersionModel source, final CatalogVersionModel target)

CodePudding user response:

I solved the problem, so I'll post the answer in case someone in the future will need it:

final CatalogVersionSyncJobModel syncJobModel = (CatalogVersionSyncJobModel) catalogSynchronizationService .getSyncJob(source, target, code);    
catalogSynchronizationService.performSynchronization(Collections.singletonList(product), syncJobModel, getSyncConfig());
  • Related