I have a query that is trying to grab a number of details from a list of defects:
<code>String useIndexPrimary = "USE INDEX (PRIMARY)";
TypedQuery<Defect> query = getEntityManager().createQuery("select d from "+getEntityName()+" d " + useIndexPrimary + " WHERE d.id in :defectIds", Defect.class);
query.setParameter("defectIds", ids);
</code>
<code>String useIndexPrimary = "USE INDEX (PRIMARY)";
TypedQuery<Defect> query = getEntityManager().createQuery("select d from "+getEntityName()+" d " + useIndexPrimary + " WHERE d.id in :defectIds", Defect.class);
query.setParameter("defectIds", ids);
</code>
String useIndexPrimary = "USE INDEX (PRIMARY)";
TypedQuery<Defect> query = getEntityManager().createQuery("select d from "+getEntityName()+" d " + useIndexPrimary + " WHERE d.id in :defectIds", Defect.class);
query.setParameter("defectIds", ids);
Which basically translates to:
<code>SELECT d FROM DefectConcrete d USE INDEX(PRIMARY) WHERE d.id IN defects"
</code>
<code>SELECT d FROM DefectConcrete d USE INDEX(PRIMARY) WHERE d.id IN defects"
</code>
SELECT d FROM DefectConcrete d USE INDEX(PRIMARY) WHERE d.id IN defects"
When I try to execute the code I get
<code>2024-07-22 12:01:27,936 [pool-177-thread-2] ::: ERROR com.optimyth.csaas.infrastructure.queues.spring.AnalysisLifeCycleManager -
java.lang.RuntimeException: Could not process stream for Diff defect.
...
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: USE near line 1, column 77 [select d from com.optimyth.csaas.metamodel.implementations.DefectConcrete d USE INDEX (PRIMARY) WHERE d.id in :defectIds]
</code>
<code>2024-07-22 12:01:27,936 [pool-177-thread-2] ::: ERROR com.optimyth.csaas.infrastructure.queues.spring.AnalysisLifeCycleManager -
java.lang.RuntimeException: Could not process stream for Diff defect.
...
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: USE near line 1, column 77 [select d from com.optimyth.csaas.metamodel.implementations.DefectConcrete d USE INDEX (PRIMARY) WHERE d.id in :defectIds]
</code>
2024-07-22 12:01:27,936 [pool-177-thread-2] ::: ERROR com.optimyth.csaas.infrastructure.queues.spring.AnalysisLifeCycleManager -
java.lang.RuntimeException: Could not process stream for Diff defect.
...
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: USE near line 1, column 77 [select d from com.optimyth.csaas.metamodel.implementations.DefectConcrete d USE INDEX (PRIMARY) WHERE d.id in :defectIds]
I think I am using “USE INDEX” in the correct place, but I am unsure why am I getting the “unexpected token” issue.