保存时发生grails错误:无法在只读事务中执行nextval()

保存时发生grails错误:无法在只读事务中执行nextval(),grails,Grails,在Grails中“从头开始”(在代码中而不是在表单中)创建对象时遇到问题。以下是控制器(评估)中方法的代码片段 结果是出现以下错误: Class org.postgresql.util.PSQLException Message ERROR: cannot execute nextval() in a read-only transaction id映射到Vol类中的生成器: static mapping = { id column:'vol_id' id genera

在Grails中“从头开始”(在代码中而不是在表单中)创建对象时遇到问题。以下是控制器(评估)中方法的代码片段

结果是出现以下错误:

Class
org.postgresql.util.PSQLException
Message
ERROR: cannot execute nextval() in a read-only transaction
id映射到Vol类中的生成器:

   static mapping = {
    id column:'vol_id'

    id generator: 'sequence',params:[sequence:'scan_sequence']
}
我真的不明白如何将保存视为只读事务。我尝试在我的域类上乱搞@transactional设置,首先将readOnly设置为false,然后删除@transactional设置,但它没有改变任何事情。看起来我应该寻找使用数据库序列的替代方案。你觉得怎么样

更新
从上述代码所在的控制器中删除readonly=true。但是删除它有什么副作用?

问题是,为什么要在只读事务中执行写操作?如果您正在执行写入操作,那么删除
readOnly=true
绝对是正确的做法


如果只执行读取,则不应将其删除。原因是使用
readOnly=true
可以提高性能,因为Hibernate不需要对只读事务执行脏检查。

谢谢。答案是readOnly=true是在搭建过程中默认添加的。
   static mapping = {
    id column:'vol_id'

    id generator: 'sequence',params:[sequence:'scan_sequence']
}