Grails StaleObjectException with Dynamic Finder (Hibernate) -


i have batch job consistently throws stale object exceptions on dynamic finder. ideally not running orm solution job, have no choice. exception occurs in formulatagservice, being called formulabatchpopulatorservice. application being run on 2 servers using 1 database. 1 server performs batch processing.

my questions are: a) why simple select statement, resulting in domain object instance no changes being made object during given transaction persisted in session, resulting in stale object exception? b) possible sorting being done on formula.tags being persisted @ end of transaction, causing staleobjectexception if else modifying formula on different server?

note, did change service read-only, , still stale object exception. appreciated.

formula tag service

@cacheable("formulajob")       def getformulabyteachertagsordefaultbatchjob(long evaluationtemplateid, list teachertags) {           long formulabytagsid = existsformulawithsametagsbatchjob(evaluationtemplateid, teachertags)            if (defaultformulaforevaluationtemplate.get(evaluationtemplateid) == null && formulabytagsid ==                  null) {                return null;           }          long defaultformulaid = defaultformulaforevaluationtemplate.get(evaluationtemplateid).formulaid         return formulabytagsid ?: defaultformulaid     }      def existsformulawithsametagsbatchjob(long evaluationtemplateid, list tags){        // line below throwing stale object exceptions         def formulas = formula.findallbyextevaluationtemplateidandisactive(evaluationtemplateid, true)          (formula formula: formulas) {             def formulatags = formula.tags             if (existstagmatchignoringblanktags(tags, formulatags)) {                 def id = formula.id                 formula.discard()                 return id             }         }     }      @cacheevict(value='formulajob', allentries=true)     def resettags(){     }      def existstagmatchignoringblanktags(list tagstocompare, list tagsexisting) {           if (!tagstocompare || !tagsexisting) {               return false            }             else {                return tagstocompare?.sort() == tagsexisting?.sort()             }     } 

formulabatchpopulatorservice snippet

   //doing below improve performance of batch processing          if(index%250==0){              cleanupgorm()              formulatagservice.resettags()  //cache-evict in formulatagservice          }           def cleanupgorm(){             def session = sessionfactory.currentsession             session.flush()             session.clear()             propertyinstancemap.get().clear()         } 

i believe answer correct:

b) possible sorting being done on formula.tags being persisted @ end of transaction, causing staleobjectexception if else modifying formula on different server?

if sort tags , it's list, believe groovy in place i.e. sorts original list , returns it. list persisted @ 1 of following times:

  1. end of transaction
  2. end of request
  3. the next time db query executed in current session (e.g. findby flush session)

it's persisted index field has changed considered dirty gorm / hibernate.

i have similar issue, resulting in same problem. came across while verifying see if others faced it.

not sure what's going on read part! service transactional?


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -