I have a very similar problem (if not the exact same one)
When using a SQL statement with a subquery in the many-to-one formula property, the parser will add the table qualifier to one of the expressions of the where clause.
For example:
formula="(select * from (select a.pk_id from table1 a where a.fk_id=fk_id order by a.pk_id desc) where rownum = 1)"
Which results in:
...(select * from (select a.pk_id from table1 a where a.fk_id=table20_.cat_id order by a.pk_id desc) where rownum = 1) ...
When I manually remove hibernate's alias in Oracle, the query works fine.
Does anyone else found any workarounds?
I want to think that perhaps I'm doing something wrong rather than there being a bug in hibernate. I'd have a hard time believing that no one else is using formula this way.
Other references of the same problem:
http://forum.hibernate.org/viewtopic.php?t=949494
Here's a workaround, although kinda vague:
http://thebogles.com/blog/2005/08/hibernate-formula-properties-bug-and/