Hibernate 6.6.x JpaCriteriaInsertSelect

I’m trying to perform an “INSERT INTO … SELECT …” using “JpaCriteriaInsertSelect” in Hibernate 6.6.
I build the query with “query.multiselect(…columns)” and assign it to the insert query using “insertQuery.select(query)”, but it throws the following error:

org.hibernate.query.SemanticException: Expected insert attribute count [0] did not match Query selection count […]

How can I explicitly specify the target columns to insert into in Hibernate 6.6, given that “insertQuery.getTarget()” returns a “JpaRoot” which doesn’t expose a “.set(…)” or “.path(…)” method?

JpaCriteriaInsertSelect has a method setInsertionTargetPaths that you will have to call with the paths.

1 Like