Hibernate<生成器>困惑生成器>
我读过一些关于休眠的教程。我仍然感到困惑。如果发生关联,生成器是否会发生变化。有人可以根据他们的经验很好地解释如何使用它,因为这是我所有问题(例如违规)的根源。
I have read several tutorial concerning the for hibernate. I'm still getting confusion. Does the generator changes in case of associations. Can someone explain well according to their experience that worked how to use this because this is the source of all my problems such as violations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解你的问题,你是在问,什么是生成器以及它们如何与关联一起使用?
第一个答案很简单:生成器定义了为对象分配 id 的策略。
第二个答案是:取决于你如何建立你们的关系。例如,查看基于主键的唯一一对一的文档
http://docs.jboss.org/hibernate/core/3.5/reference/en/html/mapping.html#mapping-declaration-onetoone
这里是生成器类一侧的设置为“foreign”,这是一种特殊情况,因为两个表共享相同的 id。
请注意另一个一对一的示例,在这种情况下,关系的一侧不会分配任何生成器。
如果您遇到持久性问题,我建议您执行以下 2 项:
If I understand your question correctly, you are asking, what are generators and how are they used with associations?
The first answer is easy: Generators define a strategy for assigning ids to objects.
The second answer is: depends on how you set up your relationships. For example look at the documentation for a unique one-to-one based on primary key
http://docs.jboss.org/hibernate/core/3.5/reference/en/html/mapping.html#mapping-declaration-onetoone
here the generator class of one side is set to 'foreign', which is a special case because two tables are sharing the same id.
Note the other one-to-one example, in that case no generator is assigned on one side of the relationship.
If you are having issues with persistence I suggest the following 2 items