I don't want to advertise, but I implemented a library that works on top of hibernate which lets you use CTEs. I personally use it with PostgreSQL and DB2.