Slower performance after upgrading hibernate from 5.6.15.Final to 6.2.2.Final

We have recently upgraded our application to hibernate 6. After upgrade, its taking double the time (it used to take before upgrade) to run the journey. I have printed the stats and have one observation.

Before upgrade:
Session Metrics {
425000 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
191800 nanoseconds spent preparing 2 JDBC statements;
5565500 nanoseconds spent executing 2 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
0 nanoseconds spent performing 0 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)
}

After upgrade:
Session Metrics {
485400 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
159100 nanoseconds spent preparing 2 JDBC statements;
12265000 nanoseconds spent executing 2 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
0 nanoseconds spent performing 0 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)
}

The time taken to acquire JDBC connection and to execute statements has increased after upgrade.
Any thing you can suggest on this? Any leads to investigate this issue further will also be helpful. Please let us know if you need any more information. Thanks.

Clearly the SQL statements that are run take longer, but it’s impossible to say what is going on without you showing the SQL that was executed with ORM 5 and 6.

Please find the queries below.

After Upgrade queries:
select t1_0.column1,t1_0.cl2,t1_0.column3,t1_0.column4,t1_0.column5,t1_0.column6,t1_0.column7,t1_0.vol8 from my_table1 t1_0 where t1_0.column1=?

select t3_0.column1,t3_0.column2,t2_0.column1,t2_0.column2,t2_0.column3,t2_0.column4,t2_0.column5,t2_0.column6,t2_0.column7,t2_0.column8,t2_0.column9,t2_0.column10,t2_0.column11,t2_0.column12,t2_0.column13,t2_0.column14,t2_0.column15,t2_0.column16,t2_0.column17,t2_0.column18,t2_0.column19,t2_0.column20,t2_0.column21,t3_0.column3,t3_0.column4,t3_0.cl5,t3_0.column6,t3_0.column7 from my_table3 t3_0 left join my_table2 t2_0 on t2_0.column1=t3_0.column8 where t3_0.column1=?

Only differences observed in queries generated in older and newer versions is
older version queries had

  1. column aliases in all the queries
  2. in second select statement its left outer join (its left join in queries generated after upgrade)

Apart from these syntactic differences (column aliases, missing outer), the SQL queries appear to be the same, so any performance difference you observe is most probably just your database taking a little longer to run a statement from time to time.