`
qixin000
  • 浏览: 20899 次
  • 性别: Icon_minigender_1
  • 来自: 黑龙江
文章分类
社区版块
存档分类
最新评论

Grails 的一个错误:a different object with the same identifier value ...

阅读更多
这是一个hibernate中的错误:a different object with the same identifier value was already associated with the session
grails程序开发过程中不知道动了哪里,导致了上述问题的产生,网上有的说使用merge,refresh,clear来解决问题,但,实际上都没有真正解决问题,要找到产生问题的原因才行,否则,一个地方使用merge但是其他地方又出现了问题,还有的地方改成merge之后,还出现了乐观锁问题!

最后,没有办法,使用了我的无敌必杀技,排除法,把我最近的版本文件一个一个的移除,最终找到了问题的出处,是Domain中使用了
static constraints = {
        username(blank: false)
        username(unique: 'gameZone')
        gameZone(blank: false);
    }

这段代码我是想约束username,gamezone成为唯一索引,注释掉,问题就没有了!
将此处代码改成其他相似的方法吧!
static mapping = {
        id composite: ['username','gameZone']
    }
    static constraints = {
        username(blank: false)
        gameZone(blank: false);
        //username(unique: 'gameZone');
    }


这种问题在正常的Grails开发中不会出现,但是如果你自己想在src/groovy中加入自己的一些有趣的东西时,那里用到domain,就可能产生这个问题了!
==================
Grails还有人用吗,我用着挺好的!!希望Grails越来越好!

转载请加链接:http://qixin000.iteye.com/blog/2087404
分享到:
评论
1 楼 苦逼的程序员 2014-08-13  
有人用,我很喜欢

相关推荐

Global site tag (gtag.js) - Google Analytics