I used static scaffolding to create CRUD-methods for my Test
domain class. When using the created TestController
only I had no problems whatsoever saving new Test
objects. However, I wanted to extend the functionality and implemented a corresponding TestService
class. Doing so I now always get an error on saving a Test
object: Connection is read-only. Queries leading to data modification are not allowed
And here it started to malfunction. Following the code of TestService
. If I understood it correctly, it would not be necessary to use the @Transactional
annotation with the two save
and delete
methods as they would inherit that functionality directly from the class.
package test.services
import grails.transaction.Transactional
import test.Test
@Transactional
class TestService {
@Transactional(readOnly = true)
def tests() {
Test.list()
}
@Transactional(readOnly = true)
def count() {
Test.count()
}
@Transactional
def save(test) {
test.save()
}
@Transactional
def delete(test) {
test.delete()
}
}
Here is also the code for saving a Test
object in the TestController
:
def save(Test test) {
if (testInstance == null) {
notFound()
return
}
if (testInstance.hasErrors()) {
respond testInstance.errors, view:'create'
return
}
testService.save(testInstance)
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.created.message', args: [message(code: 'test.label', default: 'Test'), testInstance.id])
redirect testInstance
}
'*' { respond testInstance, [status: CREATED] }
}
}
The only thing I changed is the line which states testService.save(testInstance)
. Before that, the scaffolding process put testInstance.save flush: true
I don't really see a mistake. Especially, as another domain class' objects can be saved without problems using more or less the same configuration.
Any help would be appreciated!