简体   繁体   中英

Why does hibernate create different column aliases for same query in different JVM instances?

When I monitor SQL queries generated by hibernate in my Java app, there are column aliases for each column used in the query. But the column aliases are suffixed with different numbers for different JVM instances.

For example:

select user0.ID as ID1_276_,
user0.DESCRIPTOR_ID as DESCRIPTOR10_276_,
user0.USER_ID as USER11_276_ 
from CI_USER user0
where ...

But the suffixes in the column aliases keep changing when the app is restarted. I am not sure exactly what the logic or formula to these suffixes is, ie _276_ . Sometimes, the same query shows something like the following:

select user0.ID as ID1_144_,
user0.DESCRIPTOR_ID as DESCRIPTOR10_144_,
user0.USER_ID as USER11_144_ 
from CI_USER user0
where ...

Only the column aliases keep changing. The table aliases stay same. Could someone help in pointing how hibernate comes up with these numbers in suffixes? Also, can I stop these suffixes altogether? I want queries without column aliases or with same column aliases.

One of the side-effects caused by different column aliases in Oracle is that the same SQL explain plan can't be used, since it is locked to a specific query.

I think it is an Oracle's bug. An alias doesn't change the query!

Our solution is in persistence.xml

<exclude-unlisted-classes>true</exclude-unlisted-classes>

So hibernate give the same aliases after reboot!

By developing next app version: you must keep the entities order in persistence.xml. If you insert 'A' entity before existing 'B', then B and B's column-s aliases will be different.

Does anybody have a better solution?

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