I have a Grails service that is marked as transactional and it does a lot of things.
I add code to this method and do not get the results that I expect when I pass it:
- I have code that calls
.save()that cannot be seen in the MySQL backend until the whole method is completed. This is what I expect, given that the service method is transactional. - I have other code that calls
.save()that can be seen in MySQL before the service method completes. I do not understand this, and I do not understand the difference between this and 1. - I have more code that I use
groovy.sql.Sqlto insert into the database. I assume this goes beyond Grails transaction processing, so the fact that this happens before the method completes makes sense. Can I get Grails to manage this inside a transaction?
Please forbid me any errors in my assumptions. Here is the code:
Main service method
public void updateDb(Date date) {
if (createResults() > 0) {
createA()
createB()
}
}
createA
A a = new a()
a.user = user
a.week = week
a.save()
createB
userWeek = new UserWeek(user: user)
userWeek.number = 1
userWeek.save(flush: true)
createResults
String insert = "insert into ..."
Sql sql = new Sql(dataSource)
sql.execute(insert)
I added flush:trueto make it flush, but now I understand that it’s easy to merge sleep mode, but not actually commit the transaction, since it is transactional. What am I doing wrong?
source
share