Reputation: 11
I have an issue with obtaining a session inside event handler method. Grails version: 3.0.11
So, the code itself:
class FooController {
def notifyFoo(Long id) {
notify('Foo:foo', id)
sendSuccessMessage(message(code: 'Message.Text.Success'))
}
}
@Consumer
class BarService {
static transactional = false
@Selector('Foo:foo')
@Transactional
def onFoo(Long fooId) {
Baz baz = Baz.findByFooId(fooId)
baz.bazProp++
**baz.save()** /*Here i get the error about 'No session found'*/
}
}
I have tried different ways to deal with this issue:
In any case i get the same error: org.hibernate.HibernateException: No Session found for current thread
Can anyone help me with my issue? What am i doing wrong?
Upvotes: 1
Views: 1295
Reputation: 187399
You shouldn't combine static transactional = false
and @Transactional
in the same service - use one or the other:
static transactional = false
static transactional = true
In Grails 3.X the static annotation is deprecated, so only annotations should be used.
Upvotes: 2