注释使Hibernate会话的控制器方法;只读;

注释使Hibernate会话的控制器方法;只读;,hibernate,grails,transactional,Hibernate,Grails,Transactional,我有一个应用程序,它有一个方法,由于某种原因我搞不清楚,它正在保存我在controller方法末尾加载的对象,尽管我指定它不应该保存 def testMethod( Long id ) { def target = SampleDomain.read( id ); // use target in a further query, but don't change target at all // I've checked, and target.isDirty() i

我有一个应用程序,它有一个方法,由于某种原因我搞不清楚,它正在保存我在controller方法末尾加载的对象,尽管我指定它不应该保存

def testMethod( Long id ) {
    def target = SampleDomain.read( id );

    // use target in a further query, but don't change target at all
    // I've checked, and target.isDirty() is false here

    target.discard()
    render( view: 'blah', model: [ /* this model does NOT contain the target */ ] )
}
出于某种原因,如果我打开logSql,我可以看到目标对象在这个方法的末尾被保存,即使我使用了“read”和“discard”。version字段似乎是表中唯一更改的db字段

是否有某种方法对该方法进行注释,以确保在控制器方法的会话期间不执行“更新”?我承认没有完全了解@Transactional注释的可能参数


我正在使用GrailsV2.2.4。

这似乎比我想象的要容易。我只需要事务注释的只读参数:

@Transactional(readOnly = true)
def testMethod( Long id ) {
    def target = SampleDomain.read( id );

    // use target in a further query, but don't change target at all
    // I've checked, and target.isDirty() is false here

    render( view: 'blah', model: [ /* this model does NOT contain the target */ ] )
}
我仍然不知道为什么在我使用discard()方法后它会更新对象。。。但现在我甚至不需要它