简体   繁体   中英

Hibernate generates extra query

I have 2 tables A and B . I write hql like a.key=? and 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). Then it execute same query 4 times. first iteration takes 100 parameters in 'in' clause, then 50, then 25 and then 4.

I don't understand why it can't execute query buy giving 179 elements in single query

On your relation from A to B you most probably have:

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.

Note that the a.id=b.id part of your query rings a bell that your OO design and ORM mapping is not correct. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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