Castle ActiveRecord 在 CreateAndFlush 上从错误的表返回 ID
我在仓库项目中使用 Castle ActiveRecord。我有几个经常更新的表:infeed、stack、stack_location。如果发生很多事情(添加输入、形成堆栈),有时调用 CreateAndFlush 后在对象上设置的 id 是来自另一个表的 ID。数据库是MySQL,ID列是int(11)而不是null auto_increment主键。我使用 PrimaryKeyType.Native 作为 ID 属性。
我需要直接调用flush,因为我需要ID将其写入PLC,PLC稍后会将其交给我。我的应用程序是多线程的,但如果我是正确的,当所有这些都出错时,只有一个线程写入数据库。我没有任何标记为易失性的东西,也没有阻止多个线程访问数据库的锁,但我认为 Castle ActiveRecord 会在适当的地方进行锁定。
I'm using Castle ActiveRecord in a warehouse project. I have several tables that get frequently updated: infeed, stack, stack_location. If a lot is happening (infeed is added, stacks are formed) sometimes the id that is set on an object after calling CreateAndFlush is the ID from another table. The database is MySQL, the ID columns are int(11) not null auto_increment primary key. I use PrimaryKeyType.Native for the ID property.
I also suffered from the following issue:
How to retrieve the last insert ID in Castle ActiveRecord?
but only with my infeed table (and I normally have something like 4 stacks / infeed). I added a catch to that situation with a 5000ms sleep and a SaveAndFlush afterwards, which makes sure I get an ID at that point.
I need to call flush directly because I need the ID to write it to a PLC which will hand it to me at a later point. My application is multi-threaded, but if I'm correct there's just one thread writing to the database when all of this goes wrong. I don't have anything marked as volatile, there are no locks in place preventing database access from multiple threads, but I assume Castle ActiveRecord does locking where appropiate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如对我的问题的评论中已经提到的:
我遇到的所有问题都没有再出现。
As already mentioned in a comment on my question:
All issues I had have not returned anymore.