我对在外键上使用一对一关联或者在主键上使用一对一关联有什么好处有疑问,我已经阅读了hibernate的文档: docs.jboss/hibernate /orm/3.3/reference/en/html/associations.html#assoc-unidirectional-121 有人可以告诉我详细的使用第一或第二个实施的好处吗?
另一个问题,我有一个用户和周长(用户---->周长)之间的一对一的单向关系,我想用基于外键。 我可以改变方向(User< ---- Perimeter),所以表格用户保持不变? 我认为这是不合理的(perimeter.getUser()!!!),但它在技术上是可能的?
解决方案除了JB Nizet提到的优点之外,还有一个人告诉我,基于外键的一对一比较灵活。让我们考虑我对外键(用户< ---外围)使用一对一,如果应用程序的需求变化需要多个用户的任何外围,如果我共享主键,我会重构要做得更多。但是,当我使用外键时,我所做的只是放松唯一的约束;)
i have questions about what is the benefits of using a one-to-one association on foreign key or a one-to-one association on primary key, I've read the documentation of hibernate available at : docs.jboss/hibernate/orm/3.3/reference/en/html/associations.html#assoc-unidirectional-121 can someone tell me with details the plus of using the first or the second implementation?
another question, i'have a one-to-one unidirectional relationship between User and Perimeter (User ----> Perimeter) and i want to use the association based on the foreign key. could i reverse the direction into (User <---- Perimeter) so the table User stay intact? I think that is not reasonable (perimeter.getUser() !!!) but it's technically possible?
解决方案In addition to advantages mentioned by JB Nizet and thanks to another person told me that the one-to-one based on foreign key is more flexible. let's consider that i use a one-to-one on foreign key (User <--- Perimeter) , if the requirements of the application changes to need multiple Users for any Perimeter, If i shared the primary key, I'll have much more refactoring to do. But as i used the foreign key, all i do is relax the unique constraint ;)
更多推荐
休眠一对一(在外键上)与一对一(在主键上)
发布评论