Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Same Query Multiple Aliases and Performance Issue

Can someone explain why does Hibernate generate different aliases for the same query?(ABC1_25, ABC1_27 ...)

How can Hibernate be configured to reuse the same queries with same aliases? How can the query be cached or made optimal?

The application I am working with is generating same queries with different aliases as shown below:

 SELECT abc0_.ATTR_ID AS ABC1_25_,
     abc0_.ALLOW AS ALLOW2_25_,
     abc0_.ALTER_DATE AS ALTER3_25_,
     abc0_.CREATE_DATE AS CREATE6_25_,
 FROM ABCTABLE abc0_
 WHERE abc0_._ID = :1

 SELECT abc0_.ATTR_ID AS ABC1_27_,
     abc0_.ALLOW AS ALLOW2_27_,
     abc0_.ALTER_DATE AS ALTER3_27_,
     abc0_.CREATE_DATE AS CREATE6_27_,
 FROM ABCTABLE abc0_
 WHERE abc0_._ID = :1

This is causing processor and memory consumption.

I came across this link: Hibernate produce different SQL for every query but did not find an answer.

like image 903
aces. Avatar asked Dec 31 '25 21:12

aces.


1 Answers

Maybe you have several instances of the SessionFactory, instead of using a singleton. That's what the OP of the other question found.

like image 129
Frank Pavageau Avatar answered Jan 03 '26 10:01

Frank Pavageau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!