简体   繁体   English

Hibernate生成额外的查询

[英]Hibernate generates extra query

I have 2 tables A and B . 我有2张桌子A和B。 I write hql like a.key=? 我像a.key =? and a.id=b.id 和a.id = b.id

It generates extra query than needed. 它会生成多余的查询。

First query is from to get elements which matches give a.key (it has 179 elements). 第一个查询是从获取与给定a.key匹配的元素(它有179个元素)。 Then it execute same query 4 times. 然后它执行相同的查询4次。 first iteration takes 100 parameters in 'in' clause, then 50, then 25 and then 4. 第一次迭代在“ in”子句中采用100个参数,然后分别是50个,25个和4个。

I don't understand why it can't execute query buy giving 179 elements in single query 我不明白为什么它不能执行查询购买,在单个查询中给出了179个元素

On your relation from A to B you most probably have: 在从A到B的关系中,您最可能具有:

batch-size="100"

and possibly: 并可能:

fetch="select"

you could change that to: 您可以将其更改为:

fetch="join"

or increase the batch size to 200 and see what happens. 或将批次大小增加到200,然后看看会发生什么。

Note that the a.id=b.id part of your query rings a bell that your OO design and ORM mapping is not correct. 请注意, a.id=b.id部分敲响了您的OO设计和ORM映射不正确的提示。 You need to use relations and let hibernate do the job (in this case the joins) for you. 您需要使用关系并让休眠状态为您完成工作(在这种情况下为联接)。 If this is the case then the above suggestions are not applicable until you map your entities correctly. 如果是这种情况,那么以上建议在您正确映射实体之前不适用。

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

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