Hibernate criteria with multiple joins does not handle the order of join

Description

Hi,

I have a criteria with many inner join (about 13-14), but the generated SQL query has a different order.

This causes performance problems because the SQL query takes about 140ms to be executed, and the criteria query (and SQL generated query) takes about 3 minutes !!

See linked files : SQL_expected, SQL_generated by criteria, Criteria_written.

Attachments

3

Activity

Show:

Former user March 30, 2019 at 2:03 AM

Hibernate legacy org.hibernate.Criteria is considered deprecated. See http://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#appendix-legacy-criteria.

You should use a JPA criteria query instead.

It is unlikely that the Hibernate team will work on a fix for this issue. If you provide a pull request with a test an fix, we may consider fixing it.

Christian Beikov March 27, 2019 at 8:43 PM

Many DBMS handle SQL with literals differently than SQL with parameters which is probably the cause for the different performance you see. Note that the performance is data dependent. The order of the joins in the SQL is irrelevant. SQL is a declarative language and will optimize/reorder the joins anyway. What you need is literal inlining or some indexes. Talk to your DBA to see why the query is slow.

Details

Assignee

Reporter

Affects versions

Priority

Created March 25, 2019 at 1:24 PM
Updated March 30, 2019 at 2:03 AM