java constants in hibernate's hql cause performance issues

In a multi-threaded environment, when hibernate converts hql to sql, it will frequently call the method in the classloader to load the class. In some middleware (such as tomcat), the classloader is a synchronous operation when loading a class. This combination significantly reduces the performance of the application.

 

related articles

https://hibernate.atlassian.net/browse/HHH-10746

https://hibernate.atlassian.net/browse/HHH-4959

 

In hibernate version 5.2.6, this problem was modified and the configuration was added

hibernate.query.conventional_java_constants

The default value is true, that is, references to java constants are not supported in hql

 

E.g:

from Table t where t.c_bh=com.xxx.Table.N_XXX

Will not try to parse "t.c_bh", but will try to parse " com.xxx.Table.N_XXX "

 

The previous version of hibernate, when encountering "xx.xx" in hql, will call the classloader to try to load the class, which will cause the classloader to load many non-existing classes (the call overhead is high), which is the reason for the performance degradation.

 

Stack 1:

	at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:390)
	- waiting to lock <0x00000007315a3870> (a org.eclipse.jetty.webapp.WebAppClassLoader)
	at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:383)
	at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:95)
	at org.hibernate.util.ReflectHelper.getConstantValue(ReflectHelper.java:122)
	at org.hibernate.hql.ast.QueryTranslatorImpl$JavaConstantConverter.handleDotStructure(QueryTranslatorImpl.java:569)
	at org.hibernate.hql.ast.QueryTranslatorImpl$JavaConstantConverter.visit(QueryTranslatorImpl.java:564)
	at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst (NodeTraverser.java:40)
	at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst (NodeTraverser.java:42)
	at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst (NodeTraverser.java:42)
	at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst (NodeTraverser.java:41)
	at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst (NodeTraverser.java:42)
	at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst (NodeTraverser.java:41)

 

Stack 2:

	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:171)
	at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
	at org.hibernate.util.ReflectHelper.getConstantValue(ReflectHelper.java:122)
	at org.hibernate.hql.ast.QueryTranslatorImpl$JavaConstantConverter.handleDotStructure(QueryTranslatorImpl.java:569)
	at org.hibernate.hql.ast.QueryTranslatorImpl$JavaConstantConverter.visit(QueryTranslatorImpl.java:564)
	at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst (NodeTraverser.java:40)
	at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst (NodeTraverser.java:41)
	at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst (NodeTraverser.java:41)
	at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst (NodeTraverser.java:41)
	at org.hibernate.hql.ast.util.NodeTraverser.traverseDepthFirst(NodeTraverser.java:33)
	at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:254)
	at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326551290&siteId=291194637