Hibernate duplicate SQL alias issue

Hi I was facing duplicate alias with column ID. I changed my query as mentioned below but nowt working

@Query(value = " SELECT DM.ID as name1 , DT.ID as name2 from "
+ "AUDITS DM INNER JOIN "
+ "AUDITS_INFO DT ON DM.ID = DT.ID " ,nativeQuery = true)

As ID is the column in both table . Now I am getting after using alias.

Unable to find column position by name: ID [Invalid column name] [n/a]"

Can you please help me to correct the query

Please share the entity model and how you are invoking the query, as well as the full stack trace.

Here is the full stack trace
[06:44:17.423] [http-nio-8080-exec-2] [WARN ] o.h.e.jdbc.spi.SqlExceptionHelper - [0499ff1e-d249-4979-819b-8b9183d753a0] - SQL Error: 17006, SQLState: 99999
"[06:44:17.424] [http-nio-8080-exec-2] [ERROR] o.h.e.jdbc.spi.SqlExceptionHelper - [0499ff1e-d249-4979-819b-8b9183d753a0] - Invalid column name
"EXCEPTION OCCOURED org.springframework.orm.jpa.JpaSystemException: Unable to find column position by name: ID [Invalid column name] [n/a]
[Ljava.lang.StackTraceElement;@24e529ef
Print org.springframework.orm.jpa.JpaSystemException: Unable to find column position by name: ID [Invalid column name] [n/a]
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:321)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:230)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:550)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:152)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:134)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:218)
at jdk.proxy2/jdk.proxy2.$Proxy219.findAllAuditsByDossierIdAndOriginApplication(Unknown Source)

on the below method invoking query. Sorry Can’t share the much code

@Query(value = " SELECT DM.ID as name1 , DT.ID as name2 from "

  • "AUDITS DM INNER JOIN "
  • "AUDITS_INFO DT ON DM.ID = DT.ID " ,nativeQuery = true)
    List findAllAuditHistory(@Param(“id”) ;

The stack trace does not show where the error originates from, just where Spring wraps and rethrows the exception.
Without the entity model I can’t really help you, but either way, it looks like you have to use a result set mapping or you simply remove the second select item.