caching - Why does turning on @Cacheable cause my transaction to fail? -
i have service i'd make cacheable. i've been looking grails-cache plugin , looks promising, it's causing behavior don't understand.
consider following service:
class fooservice { def contentservice @listener void processfoo(foo foo) { dostuff(foo) foo.save(failonerror: true) } private void dostuff(foo foo) { contentservice.evaluate(foo.name) } }
now here's contentservice
definition:
class contentservice { object findsource(string name) { content.findbypath(name) ?: content.findbypath(striplocale(name)) } string evaluate(string name) { .... } }
this works fine until try add caching. first, set in config.groovy:
grails.cache.config = { cache { name 'content' } }
then in contentservice, annotate method:
@cacheable('content') object findsource(string name) { content.findbypath(name) ?: content.findbypath(striplocale(name)) }
after making these changes, processfoo
method executes every line of code , throws 1 of these on exit:
illegal arg invokation java.lang.reflect.invocationtargetexception org.springframework.transaction.unexpectedrollbackexception: transaction rolled because has been marked rollback-only
what confuses me method @cacheable
annotation isn't called fooservice
. evaluate()
method called, , there appear no issues method. why adding annotation method that's not being used in execution cause transaction rollback?
do fooservice , contentservice need behave in transaction? if not, try disabling transactional behavior of services adding line below service classes , see if helps:
static transactional = false
Comments
Post a Comment