gavin wrote:
This is a known problem affecting only sybase (stupid limitation of sybase), which has been resolved in HB3.
Hi everybody.
Unfortunately this problem also affects Oracle (Oracle9i 9.2.0.1.0 in my case). It appears, if you apply Criteria.setMaxResults(int) to the search criteria. In this case, Hibernate generates following SQL:
select * from (YOUR SQL HERE) where rownum_ > ?
And "YOUR SQL" contain 2 columns with same name. So Oracle complains " ORA-00918: column ambiguously defined".
After some hours of researching the problem, it seems to me I've found a workaround, at least for Oracle. There is a code in the class "Alias.java"
Code:
public String toAliasString(String sqlIdentifier) {
char begin = sqlIdentifier.charAt(0);
int quoteType = Dialect.QUOTE.indexOf(begin);
String unquoted = getUnquotedAliasString(sqlIdentifier, quoteType);
if ( quoteType >= 0 ) {
char endQuote = Dialect.CLOSED_QUOTE.charAt(quoteType);
return begin + unquoted + endQuote;
}
else {
return unquoted;
}
}
So, if we "quote" the second column definition, Hibernate will generate an alias for a column name, and the SQL will work!
There is an excerpt from my mapping:
Code:
<class name="AccountingClauseHistoryItem" table="ACC_HISTORY">
<composite-id>
<key-property name="parentId" column="ID_ACC"/>
<key-property name="runDate" column="RUN_DATE" type="date"/>
</composite-id>
<many-to-one name="accountingClause" column='"ID_ACC"' insert="false" update="false"/>
........and so on..........
</class>
Please note column ID_ACC is double quoted when declared in "many-to-one".