title: Hybris Entity not found exception
body: <p>We have a rather major issue in our hybris implementation with missing data base entires. We have been getting "Entity Not Found" errors. It started rather randomly on last Monday. The records that are causing errors are in the database and we can use flexi-search to find them, however many of them throw 4 or 5 errors in a row. We did a build with and Update Running System, however it did not solve the issue. Most of the errors are thrown btgresults and cartentries.
  We cannot recreated the issue in our staging or development systems.
  Here is a example of the errors in the logs:</p>
  
  <pre><code>6:41:35.587 PM  
  INFO | jvm 1 | main | 2014/06/07 22:41:35.587 | [mde.hybris.platform.util.jeeapi.YNoSuchEntityException: Entity not found ( pk = 8847902804326 name = 'de.hybris.platform.persistence.btg_BTGAbstractResult' type code = '2406' db table = 'btgresult')
  host = sop-p-ma-app-002
  source = /opt/hybris/log/tomcat/console-20140607.log
  sourcetype = java_console
      6/7/14 
  6:41:06.253 PM  
  INFO | jvm 1 | main | 2014/06/07 22:41:06.253 | [mde.hybris.platform.util.jeeapi.YNoSuchEntityException: Entity not found ( pk = 8847902411110 name = 'de.hybris.platform.persistence.btg_BTGAbstractResult' type code = '2406' db table = 'btgresult')
  host = sop-p-ma-app-002
  source = /opt/hybris/log/tomcat/console-20140607.log
  sourcetype = java_console
      6/7/14 
  6:41:06.051 PM  
  INFO | jvm 1 | main | 2014/06/07 22:41:06.051 | [mde.hybris.platform.util.jeeapi.YNoSuchEntityException: Entity not found ( pk = 8847902345574 name = 'de.hybris.platform.persistence.btg_BTGAbstractResult' type code = '2406' db table = 'btgresult')
  host = sop-p-ma-app-002
  source = /opt/hybris/log/tomcat/console-20140607.log
  sourcetype = java_console
      6/7/14 
  6:40:50.233 PM  
  INFO | jvm 1 | main | 2014/06/07 22:40:50.233 | [mde.hybris.platform.util.jeeapi.YNoSuchEntityException: Entity not found ( pk = 8832652476459 name = 'de.hybris.platform.persistence.core_Cart' type code = '43' db table = 'carts')
  host = sop-p-ma-app-002
  source = /opt/hybris/log/tomcat/console-20140607.log
  sourcetype = java_console
      6/7/14 
  6:40:50.032 PM  
  INFO | jvm 1 | main | 2014/06/07 22:40:50.032 | [mde.hybris.platform.util.jeeapi.YNoSuchEntityException: Entity not found ( pk = 8832652443691 name = 'de.hybris.platform.persistence.core_Cart' type code = '43' db table = 'carts')
  host = sop-p-ma-app-002
  source = /opt/hybris/log/tomcat/console-20140607.log
  sourcetype = java_console
      6/7/14 
  6:40:49.930 PM  
  INFO | jvm 1 | main | 2014/06/07 22:40:49.930 | [mde.hybris.platform.util.jeeapi.YNoSuchEntityException: Entity not found ( pk = 8832652410923 name = 'de.hybris.platform.persistence.core_Cart' type code = '43' db table = 'carts')
  host = sop-p-ma-app-002
  source = /opt/hybris/log/tomcat/console-20140607.log
  sourcetype = java_console
  </code></pre>
  
  <p>And a stack trace from on of the errors:</p>
  
  <pre><code>HTTP Status 500 - Entity not found ( pk = 8847703804262 name = 'de.hybris.platform.persistence.btg_BTGAbstractResult' type code = '2406' db table = 'btgresult')
  type Exception report
  message Entity not found ( pk = 8847703804262 name = 'de.hybris.platform.persistence.btg_BTGAbstractResult' type code = '2406' db table = 'btgresult')
  description The server encountered an internal error that prevented it from fulfilling this request.
  exception
  de.hybris.platform.util.jeeapi.YNoSuchEntityException: Entity not found ( pk = 8847703804262 name = 'de.hybris.platform.persistence.btg_BTGAbstractResult' type code = '2406' db table = 'btgresult')
   de.hybris.platform.persistence.GenericBMPBean.loadData(GenericBMPBean.java:259)
   de.hybris.platform.persistence.GenericBMPBean.ejbLoad(GenericBMPBean.java:148)
   de.hybris.platform.persistence.framework.RemoteInvocationHandler.performOther(RemoteInvocationHandler.java:187)
   de.hybris.platform.persistence.framework.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:107)
   com.sun.proxy.$Proxy45.getModifiedTime(Unknown Source)
   de.hybris.platform.persistence.ItemEJBImpl.getModificationTime(ItemEJBImpl.java:142)
   de.hybris.platform.jalo.Item.getModificationTimeFromPersistenceLayer(Item.java:1516)
   de.hybris.platform.jalo.Item.getLocalItemCache(Item.java:1387)
   de.hybris.platform.jalo.Item.getGetterSetterCache(Item.java:1397)
   de.hybris.platform.jalo.Item.access$1(Item.java:1395)
   de.hybris.platform.jalo.Item$CacheableItemLogic.getCacheMap(Item.java:542)
   de.hybris.platform.jalo.Item$CachedGetter.get(Item.java:668)
   de.hybris.platform.jalo.Item$CachedGetter.get(Item.java:655)
   de.hybris.platform.jalo.Item.getPersistenceVersion(Item.java:1534)
   de.hybris.platform.servicelayer.internal.converter.impl.ItemModelConverter.save(ItemModelConverter.java:630)
   de.hybris.platform.servicelayer.internal.model.impl.ModelWrapper.save(ModelWrapper.java:149)
   de.hybris.platform.servicelayer.internal.model.impl.ResolvingModelPersister.saveNewOnes(ResolvingModelPersister.java:127)
   de.hybris.platform.servicelayer.internal.model.impl.ResolvingModelPersister.persist(ResolvingModelPersister.java:95)
   de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.saveAllInternal(DefaultModelService.java:1103)
   de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.saveAll(DefaultModelService.java:1090)
   de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.save(DefaultModelService.java:735)
   de.hybris.platform.btg.dao.impl.DefaultBTGDao.createConditionResult(DefaultBTGDao.java:318)
   de.hybris.platform.btg.dao.impl.ResultCachingBTGDaoDecorator.createConditionResult(ResultCachingBTGDaoDecorator.java:241)
   de.hybris.platform.btg.condition.impl.DefaultBTGExpressionEvaluator.setConditionResultAfterEvaluation(DefaultBTGExpressionEvaluator.java:222)
   de.hybris.platform.btg.condition.impl.DefaultBTGExpressionEvaluator.evaluate(DefaultBTGExpressionEvaluator.java:142)
   de.hybris.platform.btg.condition.impl.DefaultBTGExpressionEvaluator.evaluate(DefaultBTGExpressionEvaluator.java:1)
   de.hybris.platform.btg.rule.impl.DefaultRuleEvaluator.evaluate(DefaultRuleEvaluator.java:109)
   de.hybris.platform.btg.segment.impl.DefaultSegmentEvaluator.evaluate(DefaultSegmentEvaluator.java:124)
   de.hybris.platform.btg.services.impl.DefaultBTGEvaluationService.evaluateSegment(DefaultBTGEvaluationService.java:105)
   de.hybris.platform.btg.services.impl.DefaultBTGEvaluationService.evaluateAllSegments(DefaultBTGEvaluationService.java:80)
   de.hybris.platform.btg.services.impl.DefaultBTGEvaluationService.evaluateAllSegments(DefaultBTGEvaluationService.java:62)
   de.hybris.platform.btg.services.impl.DefaultBTGEvaluationService.evaluateAllSegments(DefaultBTGEvaluationService.java:55)
   com.so.storefront.filters.btg.support.impl.DefaultBTGSegmentStrategy.evaluateSegment(DefaultBTGSegmentStrategy.java:98)
   com.so.storefront.filters.btg.BTGSegmentFilter.doFilterInternal(BTGSegmentFilter.java:48)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   com.so.storefront.filters.btg.AbstractBtgFilter.doFilterInternal(AbstractBtgFilter.java:57)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   com.so.storefront.filters.btg.AbstractBtgFilter.doFilterInternal(AbstractBtgFilter.java:57)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   com.so.storefront.filters.btg.AbstractBtgFilter.doFilterInternal(AbstractBtgFilter.java:57)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   com.so.storefront.filters.btg.AbstractBtgFilter.doFilterInternal(AbstractBtgFilter.java:57)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   com.so.storefront.filters.CrossScriptingFilter.doFilterInternal(CrossScriptingFilter.java:36)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   com.so.storefront.filters.SpecialAccountsFilter.doFilterInternal(SpecialAccountsFilter.java:470)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   com.so.storefront.filters.CustomerLocationRestorationFilter.doFilterInternal(CustomerLocationRestorationFilter.java:63)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   com.so.storefront.filters.CartRestorationFilter.doFilterInternal(CartRestorationFilter.java:133)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   com.so.storefront.filters.AnonymousCheckoutFilter.doFilterInternal(AnonymousCheckoutFilter.java:62)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
   org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
   org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
   org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
   org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
   org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:139)
   org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
   org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
   org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
   org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
   org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
   org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   org.springframework.security.web.access.channel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:144)
   org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
   org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
   org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   com.so.storefront.filters.UrlEncoderFilter.doFilterInternal(UrlEncoderFilter.java:100)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   com.so.storefront.filters.StorefrontFilter.doFilterInternal(StorefrontFilter.java:73)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   com.so.storefront.filters.cms.CMSSiteFilter.doFilterInternal(CMSSiteFilter.java:108)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   com.so.storefront.filters.RequestLoggerFilter.doFilterInternal(RequestLoggerFilter.java:79)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   com.so.storefront.filters.AcceleratorAddOnFilter.doFilter(AcceleratorAddOnFilter.java:92)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   de.hybris.platform.servicelayer.web.SessionFilter.doFilter(SessionFilter.java:73)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain.doFilterInternal(AbstractPlatformFilterChain.java:156)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   com.so.storefront.filters.UrlPathFilter.doFilterInternal(UrlPathFilter.java:85)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
   org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:256)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$StatisticsGatewayFilter.doFilter(AbstractPlatformFilterChain.java:345)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   de.hybris.platform.servicelayer.web.RedirectWhenSystemIsNotInitializedFilter.doFilter(RedirectWhenSystemIsNotInitializedFilter.java:104)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   de.hybris.platform.servicelayer.web.TenantActivationFilter.doFilter(TenantActivationFilter.java:91)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   de.hybris.platform.servicelayer.web.Log4JFilter.doFilter(Log4JFilter.java:47)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:226)
   de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain.doFilterInternal(AbstractPlatformFilterChain.java:156)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
   org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
   org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   com.so.storefront.filters.AcceleratorAddOnFilter.doFilter(AcceleratorAddOnFilter.java:92)
   org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
   org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
  note The full stack trace of the root cause is available in the Apache Tomcat/6.0.36 logs.
  </code></pre>
  
  <p>UPDATE: Just some new information, the Errors always seem to occur right as that the record is being created. Is it possible that there is some latency in our database and the record is successfully created but it isn't returned to the application?</p>
  
  <p>Also the error always appears in de.hybris.platform.persistence.GenericBMPBean.loadData(GenericBMPBean.java:259) not sure if this is intact where the error starts of if something else in the stack is calling this wrong however the documentation for GenericBMPBean is pretty clear. "Entity not found" means there is no item for a given pk. Am I wrong in assuming that according to the DB this record doesn't exist? whether because of latency or a DB error.</p>
  
  <p>The record does exist and infact was created in the same stack trace that throws the error.</p>