apache / apache/grails-core

Closure for creating key has an issue when used with @Transactional annotation

Open
#14,166 0 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-cache
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

This issue is related to https://github.com/grails-plugins/grails-cache/issues/49.

grails -v
_Grails Version: 3.3.7
Groovy Version: 2.4.15
JVM Version: 1.8.0_222_

The following service method will give the stacktrace below. Issue is with how the key is formed.
It works without the @Transactional annotation. Version of cache plugin is **4.0.3**.

```
@Transactional(readOnly=true)
@Cacheable(value='codes', key={code + '' + layer})
def getCachedData(String code, String layer){
return 'some code'
}
```

Caused by: java.lang.NoSuchMethodError: java.lang.String.plus(Ljava/lang/CharSequence;)Ljava/lang/String;
at helloworld.SimpleService$__tt__getCachedData_closure4.doCall(SimpleService.groovy:89)
at grails.plugin.cache.CustomCacheKeyGenerator.generate(CustomCacheKeyGenerator.groovy:115)
at grails.gorm.transactions.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:94)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)

Contributor guide

Open the contributing guide

Research direction

Start with the service reproducer in SimpleService.groovy:89, then inspect CustomCacheKeyGenerator.groovy:115 and GrailsTransactionTemplate.groovy:94 to trace key generation with @Transactional. Reproduce the NoSuchMethodError using Grails 3.3.7 and cache plugin 4.0.3; done means the key is generated and the cached method succeeds with the annotation.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.