A huge setParameterList list

I have a list of Integer arrays with 8000 elements.

And I installed this list of arrays in hql using the setParameterList method.

Just an example request

 return (Integer) sessionFactory.getCurrentSession().createQuery("update data where Id in (:list)").setParameterList("list", arrayList).executeUpdate(); 

but after executing the request, I got this error.

 java.lang.StackOverflowError at org.hibernate.hql.ast.QueryTranslatorImpl$JavaConstantConverter.visit(QueryTranslatorImpl.java:585) at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(NodeTraverser.java:64) at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(NodeTraverser.java:65) at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(NodeTraverser.java:66) at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(NodeTraverser.java:66) at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(NodeTraverser.java:66) at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(NodeTraverser.java:66) at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(NodeTraverser.java:66) at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(NodeTraverser.java:66) 

is there any way to solve this problem in sleep mode. perhaps this will work with pure sql query. But I just want to know if there is another way in HQL.

+4
source share
3 answers

If your list comes from another SQL query, try using WHERRE EXISTS instead.

Otherwise, you may need to update each element independently inside the loop.

IN an article about thousands of items is usually poorly handled by databases.

0
source

This issue seems to be addressed in the documentation. The authors recommend doing such operations in batches.

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/batch.html

0
source

Your query is not a valid HQL query. You missed the set clause in the request:

 update Data set foo = 7 where id in (:list) 

However, 8000 identifiers in a section in a section are many. Databases have limits on the size of the request. Oracle, for example, does not accept more than 1000 elements in an IN clause.

0
source

Source: https://habr.com/ru/post/1480076/


All Articles