简体   繁体   English

Hibernate在保存级联时加入联接

[英]Hibernate make joins on save cascade

Let´s say I have an entity A that has a relationship oneToMany with B with cascade ALL type and by default lazy. 假设我有一个实体A,该实体的关系为oneToMany与B,且其层叠类型为ALL,默认情况下为惰性。 My question now is, what happend, if now I modify A, but B keep in session exactly the same, and I save A. Hibernate will do the join with B and he will update on database, or he will keep B as hibernate proxy?. 我的问题是,如果现在我修改A,但是B保持会话完全相同,那么我会保存A。Hibernate将与B进行连接,并且他将在数据库上更新,或者他将B保留为休眠代理。 ?。

We´re facing some problems on our application, since MySQL is complaining for the maximum number of joins when we save the top level entity. 我们在应用程序上遇到一些问题,因为当我们保存顶级实体时,MySQL抱怨连接的最大数量。

  ERROR 1116 (HY000): Too many tables; MySQL can only use 61 tablesin a join

Regards. 问候。

I had a similar problem, but with eager fetched relationships. 我有一个类似的问题,但是渴望关系。 Once we changed them to lazy, the problem was gone. 一旦我们将它们更改为惰性,问题就消失了。

Hibernate shouldn't make joins with other lazy-related tables when updating only table A in your example, but best is to print out the generated SQL and see if and how it changes when you change your fetch settings. 在示例中仅更新表A时,Hibernate不应与其他与惰性相关的表进行联接,但是最好是打印出生成的SQL,并查看其在更改访存设置时是否以及如何更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM