hibernate/hibernate-orm — pull request #537 by philippn (2013-05-16 12:49:23+00:00)
Title: Bugfix for possible ORA-00918: column ambiguously defined with clazz_ pseudocolumn

Hey there,

I'm not sure if you are planning to do another maintenance release of 3.6.x. In case you do, please consider to include this fix. More precisely the one in AbstractEntityPersister.java (please ignore the other commit, I'm new to this pull request thing :) ).

This fixes a problem when heavily using union-subclass hierarchies in HQL.

Eventually, you may end up with SQL like this:

```sql
select documentex0_.id as col_0_0_, documentex0_.version as col_0_1_, categoryex2_.id as col_1_0_, categoryex2_.version as col_1_1_, categoryex2_.id as id3_, categoryex2_.version as version3_, categoryex2_.deleteflag as deleteflag3_, categoryex2_.createStamp as createSt4_3_, categoryex2_.CMMNT as CMMNT8_, categoryex2_.categId as categId8_, categoryex2_.fit as fit8_, categoryex2_.critId as critId10_, categoryex2_.FK_DESIG_ID as FK1_13_, categoryex2_.FK_DESIG_VER as FK2_13_, categoryex2_.clazz_ as clazz_ from ( select id, version, deleteflag, createStamp, categSetId, null as name, 10 as clazz_ from DOCEXPR union all select id, version, deleteflag, createStamp, categSetId, name, 12 as clazz_ from REVISIONPROF union all select id, version, deleteflag, createStamp, categSetId, name, 13 as clazz_ from PUBPROF ) documentex0_ inner join DOC_CATEG_EXPRS subexps1_ on documentex0_.id=subexps1_.FK_DOCEXPR_ID and documentex0_.version=subexps1_.FK_DOCEXPR_VER inner join ( select id, version, deleteflag, createStamp, CMMNT, categId, fit, critId, null as FK_DESIG_ID, null as FK_DESIG_VER, 5 as clazz_ from CRITEXPR union all select id, version, deleteflag, createStamp, CMMNT, categId, fit, null as critId, null as FK_DESIG_ID, null as FK_DESIG_VER, 6 as clazz_ from GROUPEXPR union all select id, version, deleteflag, createStamp, CMMNT, categId, fit, null as critId, FK_DESIG_ID, FK_DESIG_VER, 7 as clazz_ from RANGEEXPR ) categoryex2_ on subexps1_.FK_CATEGEXPR_ID=categoryex2_.id and subexps1_.FK_CATEGEXPR_VER=categoryex2_.version where categoryex2_.categId=? and clazz_=7 and categoryex2_.version=(select max(categoryex3_.version) from ( select id, version, deleteflag, createStamp, CMMNT, categId, fit, critId, null as FK_DESIG_ID, null as FK_DESIG_VER, 5 as clazz_ from CRITEXPR union all select id, version, deleteflag, createStamp, CMMNT, categId, fit, null as critId, null as FK_DESIG_ID, null as FK_DESIG_VER, 6 as clazz_ from GROUPEXPR union all select id, version, deleteflag, createStamp, CMMNT, categId, fit, null as critId, FK_DESIG_ID, FK_DESIG_VER, 7 as clazz_ from RANGEEXPR ) categoryex3_ where categoryex3_.id=categoryex2_.id group by categoryex3_.id) and documentex0_.version=(select max(documentex4_.version) from ( select id, version, deleteflag, createStamp, categSetId, null as name, 10 as clazz_ from DOCEXPR union all select id, version, deleteflag, createStamp, categSetId, name, 12 as clazz_ from REVISIONPROF union all select id, version, deleteflag, createStamp, categSetId, name, 13 as clazz_ from PUBPROF ) documentex4_ where documentex4_.id=documentex0_.id group by documentex4_.id)
```

This in turn leads to an 'ORA-00918: column ambiguously defined'. Upon further inspection, it turned out that the problem is the clazz_ pseudocolumn near

```sql
... where categoryex2_.categId=? and clazz_=7 and ...
```

because it is not qualified with the table alias.

The attached commit fixes this by prefixing it with the placeholder used for table alias replacement.

Thanks for your time!

Kind regards,
Philipp