Hibernate:会以传递方式合并多对一对象的工作吗?
您好,我知道在合并之前进行测试会将对象重新附加回会话,以防止当对象不再处于会话中时发生延迟初始化异常。
a.) 所以我有几个问题。
如果我付款-->客户(处于多对一的单向关系)和我进行
Payment payment = Payment.class.cast(session.merge(oldPayment));
客户对象是否也会重新附加到会话中,或者我是否必须为客户进行另一个合并调用。
b.) 如果付款--> 会发生什么?客户(多对一的双向关系)。比会发生什么。
c.) 如果我有超过三个层次结构的关系怎么样?
示例:酒店 -->付款-->顾客。
如果我执行 Hotel hotel = Hotel.class.cast(session.merge(unmergeHotel)),付款和客户对象也会合并到会话中吗?
谢谢
Hi I know that and tested before merge will reattach the object back to session preventing lazy initialization exception when object is no longer in session.
a.) So I have a few question.
If i payment --> customer (in a many-to-one unidirectional relationship) and I do
Payment payment = Payment.class.cast(session.merge(oldPayment));
Will customer object also be reattach into session, or do I have to make another merge call for the customer.
b.) What happen if the payment--> customer (many-to-one bidirectional relationship). What would happen than.
c.) How about if i have relationship of more than three hierarchy.
example: hotel --> payment --> customer.
If I do Hotel hotel = Hotel.class.cast(session.merge(unmergeHotel)), will the payment and customer object also be merge into session?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它是由关系的级联选项定义的。
JPA 规范的相关摘录(我猜原生 Hibernate 的
Session
接口提供了相同的语义):另请参阅:
It's defined by cascading options of your relationships.
Related exceprt from JPA Specification (I guess native Hibernate's
Session
interface offers the same semantics):See also: