2012-10-05 17 views
2

在Grails领域一个已经实现了beforeDelete如下Grails的withNewSession冲不

class Shop { 
    def beforeDelete() { 
     Shop.withNewSession { 
      Client.findAllByShop(this)*.shop = null     
     }  
    } 
} 

但客户店空值不会保存到数据库。

如果我添加手动会话冲洗

class Shop { 
    def beforeDelete() { 
     Shop.withNewSession { s2-> 
      Client.findAllByShop(this)*.shop = null   
      s2.flush() 
      s2.clear() 
     } 
    } 
} 

它的工作原理,客户开店值被置空在数据库中。

这是一个Grails错误还是我误解了文档? withNewSession是否意味着自动冲洗?

回答

3

文档(向下滚动到beforeDelete示例here)似乎意味着不需要刷新或清除会话。

Burt Beckwith已经Grails的邮件列表上也指出(见螺纹here)是手动调用flush()clear()是没有必要的withNewSession关闭。

说了这么多,似乎有一个错误报告(见细节here)使用withNewSession从Grails 2.2.1开始。

0

withNewSession给你一个新的Hibernate会话,但它不一定是事务性的。这听起来像你想用withTransaction而不是withNewSession

+0

那么你建议这样吗? 高清beforeDelete(){ Shop.withNewSession {{Shop.withTransaction Client.findAllByShop(本)*店= NULL}} } 我 –

+0

建议,除非你已经尝试过了,也没有工作。 – doelleri