简体   繁体   English

为什么 hibernate 会在不同的 JVM 实例中为相同的查询创建不同的列别名?

[英]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.当我在 Java 应用程序中监视 hibernate 生成的 SQL 查询时,查询中使用的每一列都有列别名。 But the column aliases are suffixed with different numbers for different JVM instances.但是对于不同的 JVM 实例,列别名以不同的数字作为后缀。

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_ .我不确定这些后缀的逻辑或公式到底是什么,即_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?有人可以帮助指出 hibernate 如何在后缀中提供这些数字吗? 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. Oracle 中不同列别名导致的副作用之一是不能使用相同的 SQL 解释计划,因为它被锁定到特定查询。

I think it is an Oracle's bug.我认为这是甲骨文的错误。 An alias doesn't change the query!别名不会更改查询!

Our solution is in persistence.xml我们的解决方案是在persistence.xml

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

So hibernate give the same aliases after reboot!所以hibernate在重启后给出相同的别名!

By developing next app version: you must keep the entities order in persistence.xml.通过开发下一个应用程序版本:您必须在persistence.xml 中保持实体顺序。 If you insert 'A' entity before existing 'B', then B and B's column-s aliases will be different.如果在现有的 'B' 之前插入 'A' 实体,则 B 和 B 的列别名将不同。

Does anybody have a better solution?有人有更好的解决方案吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate为不同的联接使用相同的别名 - Hibernate make same aliases for different joins 在Hibernate中使用不同的别名对同一关联进行多次联接 - Multiple joins to same association with different aliases in Hibernate JVM内部 -​​ 为什么同一段代码在不同的时间运行? - JVM Internals - Why does the same piece of code runs in different timings? 通过两个不同的JVM进程将Hibernate实例分开 - Separate Hibernate instances by two different JVM processes anomaly 为什么Hibernate记录一个实际上未执行的不同查询? - Why does Hibernate log a different query that it does not actually execute? JVM是否在两个单独的实例中实现了不同的应用程序? - Does the JVM make two separate instances of classes that are implemented in different applications? 构造resultMap以为同一集合创建不同的实例 - Constructing resultMap to create different instances for the same collection Java Hibernate JPA 创建一个实体并加入同一列引用的两个不同的表,具有相同的列名 - Java Hibernate JPA create an entity and Join two different tables referenced by the same column, with same column name Hibernate相同查询多个别名和性能问题 - Hibernate Same Query Multiple Aliases and Performance Issue Hibernate(mysql)对于同一查询返回不同的结果 - Hibernate (mysql) returns different results for same query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM