Bug 1111706

Summary: [GSS](6.3.0) NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql alias
Product: [JBoss] JBoss Enterprise Application Platform 6 Reporter: Stephen Fikes <sfikes>
Component: HibernateAssignee: Gail Badner <gbadner>
Status: CLOSED WONTFIX QA Contact: Martin Simka <msimka>
Severity: unspecified Docs Contact: Russell Dickenson <rdickens>
Priority: unspecified    
Version: 6.1.0CC: msimka, smumford
Target Milestone: ---   
Target Release: EAP 6.3.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Known Issue
Doc Text:
In this release of JBoss EAP 6 a native SQL query which specifies a column multiple times without unique aliases (e.g. "select e.id, e.title, e.id from Event e") for any simple entity (e.g. Event) fails in with the following message: ---- org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql alias [id] during auto-discovery of a native-sql query ---- This happens because Hibernate obtains the column labels from java.sql.ResultSetMetaData.getColumnLabel(). Hibernate cannot determine if the columns with the same name refer to the same value from the same entity. Rather than possibly making an incorrect assumption, Hibernate throws the exception. The workaround is to provide unique aliases for columns with the same name (e.g. "select e.id AS id1, e.title, e.id AS id2 from Event e").
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-08-11 19:07:03 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Maven based test none

Description Stephen Fikes 2014-06-20 19:03:43 UTC
Created attachment 910870 [details]
Maven based test

Description of problem:
For any simple entity (e.g. Event) a native SQL query which specifies a column multiple times (e.g. "select e.id, e.title, e.id from Event e") fails in Hibernate 4:

org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql alias [id] during auto-discovery of a native-sql query

Version-Release number of selected component (if applicable):
Hibernate 4

How reproducible:
Consistently

Steps to Reproduce:
For a simple entity, execute a native SQL query specifying one column (e.g. 'id') multiple times
	List results = session.createSQLQuery(
		"select e.id, e.title, e.id from Event e").list();

Actual results:
org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql alias [id] during auto-discovery of a native-sql query
	at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:630)
	at org.hibernate.loader.Loader.getResultSet(Loader.java:2039)
	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1832)
	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1811)
	at org.hibernate.loader.Loader.doQuery(Loader.java:899)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
	at org.hibernate.loader.Loader.doList(Loader.java:2516)
	at org.hibernate.loader.Loader.doList(Loader.java:2502)
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2332)
	at org.hibernate.loader.Loader.list(Loader.java:2327)
	at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:338)
	at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1826)
	at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:231)
	at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:157)
	...

Expected results:
The exception is not expected.

Additional info:
- The same query works as late as in Hibernate 3.3.2.GA.
- Modifying the query to use explicit column aliases works around the issue:
	"select e.id as eid1, e.title, e.id as eid2 from Event e"

Comment 2 Gail Badner 2014-06-23 20:06:11 UTC
This is an expected failure due to HHH-5992. The workaround is the appropriate way to deal with this.