问题描述
我意识到这是一个比Grails更棘手的问题。在一个负载均衡(2个节点)的环境中,我看到我的对象的ID正在跳转很多。即使没有重新启动应用程序服务器,我也会看到数字跳过10,有时候是20个数字。我怀疑休眠会话正在缓存一个序列值块。 有没有一种方法可以用grails 1.3.7来控制这种行为?基本上,我可以在服务器每次需要时从数据库中拉取nextval。
我的域对象序列声明(对于2个对象是相同的):
$ $ $ $ $ $ c $ static映射= {
id生成器:'序列',params:[sequence:'MY_SEQ']
}
我已经进入数据库并用以下DDL修改了序列:
ALTER SEQUENCE MY_SEQ NOCACHE ;
我认为这是解决此问题的最佳解决方案。有没有人看到这种方法的潜在问题?
谢谢所有!
I realize this is more of a hibernate question than Grails. In a load balanced (2 nodes) environment I see that the ids of my objects are jumping around quite a bit. Even without restarting the app server I see that the numbers skip 10 sometimes 20 numbers. I suspect the hibernate session is caching a block of sequence values. Is there a way to control this behavior with grails 1.3.7 ? Essentially I am OK with server pulling nextval from DB every time it needs one.
My domain object sequence declaration (same for 2 objects):
static mapping = {
id generator:'sequence', params:[sequence:'MY_SEQ']
}
I have since went to the database and modified the Sequence with the following DDL:
ALTER SEQUENCE MY_SEQ NOCACHE;
I think this is the best solution for this issue. Does anyone see potential problems with this approach?
Thanks all!
这篇关于针对Oracle 11g的Grails序列生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!