Suppose the following situation..
- I have declared three different datasources (datasource, datasource_b and datasource_c) in my DataSource.groovy.
- I have three different Domain Objects which use these datasources.
- In my Controller, I call a method from a service in which I save the objects a, b and c. I need that if an error occurs, none of them is saved.
So:
DataSource.groovy
environments {
development {
dataSource {
[...]
}
dataSource_b {
[...]
}
dataSource_c {
[...]
}
}
}
ObjectA.groovy
class ObjectA{
[...]
static mapping = {
//use default datasource
}
}
ObjectB.groovy
class ObjectB{
[...]
static mapping = {
datasource 'b'
[...]
}
}
ObjectC.groovy
class ObjectC{
[...]
static mapping = {
datasource 'c'
[...]
}
}
MyService.groovy
public savingObjects(ObjectA a,ObjectB b,ObjectC c){
a.save()
b.save()
c.save()
}
I am using Grails 2.4.3 and I know that methods in services are Transaccional but, for example, if error occurs when I am saving 'c', 'a' and 'b' are saved without any flush (save flush:true).
Any idea to correct this behaviour? I want to avoid using XA datasources.
Thanks!