We are using Grails [Spring+Hibernate] and have one service method with @Transactional(readOnly=true). During development & tests we were using HSQLDB and the behaviour was such that we could use .save(flush:true) and object would be saved to the database, but all other objects would be rolled back.
Everything was great accept for when we switched to Postgres. Now this settings throws back:
ERROR – transaction is read only.
EDIT:
We have to be able to rollback all the data in the transaction but still be able to save the data we require to be saved [some additional stuff, not related to the transaction, like something for logging purposes]. It don’t want to use any DB triggers to do that. We also don’t want to get Stale Object Exceptions when saving stuff after the original request was served.
Any ideas on how we could achieve that? The only thing that comes to my mind is to have some kind a registry where we would store references to modified objects and at the end drop all changes, but this is the last resort. I am sure there’s a way to tackle this issue without doing stupid things.
so we’ve found the solution.
It’s in grails jira:
http://jira.grails.org/browse/GRAILS-8513?focusedCommentId=68436&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-68436