Randomly getting "AliasCollisionException" for the same query

Hello,

We recently upgraded to Spring Boot version 3.x and Hibernate 6.5.3. Following this upgrade, we began encountering random AliasCollisionException errors during runtime. This issue has not been reproducible in our local environments.

Our application is deployed on Kubernetes (EKS), and the exception was observed only on 2 out of 4 pods. Restarting the affected pods mitigated the issue. Interestingly, we observed this exception during two consecutive production deployments.

While renaming conflicting aliases might help, it would require extensive changes across the codebase.

One puzzling aspect is that the same query works reliably when generated via QueryDSL but intermittently fails with this exception. We’re trying to understand what could be causing this inconsistency.

Any insights or suggestions on potential causes would be appreciated.

“message”:"handleGenericError occured [org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.query.sqm.AliasCollisionException: Duplicate identification variable ‘attachments’ in ‘from’ clause [join attachments as attachments join attachments as attachments]\n\tat org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:371)\n\tat org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:246)\n\tat org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:550)\n\tat org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)\n\tat org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:335)\n\tat org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:160)\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)\n\tat org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:768)\n\tat org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)\n\tat org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:768)\n\tat org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:720)\n\tat

Hello Jags.gud,
how did you define the query?
I think the exception says it all, the attachments are joined twice with the same identifier.
Not knowing anything about the datamodel nor the query makes it difficult to give any further advice.
br,
Peter