- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.7k
HHH-19396 cannot select the same column twice with different aliases while using cte #10158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HHH-19396 cannot select the same column twice with different aliases while using cte #10158
Conversation
5126bf6    to
    8b3f32e      
    Compare
  
    | Previous change was always setting  | 
8b3f32e    to
    38b7ede      
    Compare
  
            
          
                hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleType.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleType.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      6a83ba0    to
    9a986df      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting better @cigaly, there's still some things I'd like to address.
        
          
                hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleType.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleType.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleType.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      9a986df    to
    9429487      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last comment, than this looks good IMO. Please also squash the changes after applying my suggestion, thanks.
        
          
                hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleType.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      c1d91ce    to
    af39a76      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two final nitpicks, thanks @cigaly.
        
          
                hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleType.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleType.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      af39a76    to
    9ff416f      
    Compare
  
            
          
                ...re/src/test/java/org/hibernate/orm/test/subquery/MultipleIdenticalColumnsInSubqueryTest.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      …wice in same (sub)query
…mporary tables and subqueries
          Selection items representing same column in (sub)query will be represented with single instance, this will hide real alias
    9ff416f    to
    29eb98b      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| @mbellade Should I backport this to 6.6? | 
| @cigaly sure you can try | 
Jira issue HHH-19396
When creating
SqlAstQueryPartProcessingStateImplin methodorg.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter#visitQuerySpecparameterdeduplicateSelectionItemsmust be set tofalse(see comment in moved code block)When
selectStatementcontains same column more than once in methodorg.hibernate.query.sqm.tree.cte.SqmCteTable#createStatementTable,SqmCteTableconstructor will be unable to properly resolve aliases. To prevent this alias in select clause selection should be used if exist, one from selectable node should be used otherwise.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.
https://hibernate.atlassian.net/browse/HHH-19396