# Hibernate duplicate SQL alias issue

**URL:** <https://discourse.hibernate.org/t/hibernate-duplicate-sql-alias-issue/8205>\
**Category:** Hibernate ORM\
**Created:** [September 5, 2023, 2:04pm UTC](https://discourse.hibernate.org/t/hibernate-duplicate-sql-alias-issue/8205 "2023-09-05T14:04:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![neha\_pahuja](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/neha_pahuja/32/2614_2.png) [@neha\_pahuja](https://discourse.hibernate.org/u/neha_pahuja)\
**Post date:** [September 5, 2023, 2:04pm UTC](https://discourse.hibernate.org/t/hibernate-duplicate-sql-alias-issue/8205/1 "2023-09-05T14:04:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [September 5, 2023, 3:06pm UTC](https://discourse.hibernate.org/t/hibernate-duplicate-sql-alias-issue/8205/2 "2023-09-05T15:06:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![neha\_pahuja](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/neha_pahuja/32/2614_2.png) [@neha\_pahuja](https://discourse.hibernate.org/u/neha_pahuja)\
**Post date:** [September 6, 2023, 5:25am UTC](https://discourse.hibernate.org/t/hibernate-duplicate-sql-alias-issue/8205/3 "2023-09-06T05:25:13Z")

</div>

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”) ;

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [September 6, 2023, 7:45am UTC](https://discourse.hibernate.org/t/hibernate-duplicate-sql-alias-issue/8205/4 "2023-09-06T07:45:46Z")

</div>

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.
