grails ID什么时候被分配?
我正在执行 myDomainObject.save(flush: true) ,然后尝试在下一条语句中读取分配给 myDomainObject 的 id,我得到的值为“null”。
我的应用程序需要在获得新 ID 后立即使用此 ID 作为发票(通过服务发送)。
我的问题是,我需要做什么才能尽可能轻松/高效地获取分配的 ID 值?
谢谢
I'm doing myDomainObject.save(flush: true) and then attempting to read the id assigned to myDomainObject in the next statement, and I get a value of "null".
My application needs to use this id as an invoice # (to send out via a service) as soon as I can get the new id.
My question is, what do I need to do to get the assigned ID value as easily/efficiently as possible?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
保存完成后它应该就在那里。事实上,在单元和集成测试中,最好断言 id 不为空,作为持久性操作成功的简单测试。你确定保存成功吗?
查看 http://www.grails.org/doc/latest /ref/Domain%20Classes/save.html
了解如何确定错误。具体来说,部分
It should be there as soon as the save completes. In fact in unit and integration tests its a good idea to assert that the id is not null as a simple test that the persistence operation was successful. Are you sure the save is successful?
Check out http://www.grails.org/doc/latest/ref/Domain%20Classes/save.html
for how to determine errors. Specifically the part with