I found the problem from the stack.
Basically, the SQL statement here does a 'DISTINCT' clause on the id of the table, and I think the ORDER BY in this case must match what is being selected (?) - ie the id. So if I order by the id it will work.
But I do not want to order by the Id (and neither too do I want duplicates)
Now what? !
09:45:33,873 DEBUG [findByFunction3] Executing SQL: SELECT DISTINCT t0_o.DOCUMENT_ID FROM DOCUMENT t0_o, FUNCTION t1_o_function WHERE ((t1_o_function.FUNCTION_ID = ?)) AND (t0_o.FUNCTION_FK=t1_o_function.FUNCTION_ID) ORDER BY t0_o.DOCUMENT_CODE ASC
09:45:33,937 DEBUG [findByFunction3] Find failed
java.sql.SQLException: ORA-01791: not a SELECTed expression