I would like to enable user to download large (up to 20Mb) files, stored in Oracle database.
I think I should use a stream, but I don't know how to get JPA to return a stream of Large Object. Can you help?
I'm using EclipseLink.
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Pagination#Using_a_ScrollableCursor describes using a scrollable cursor to return entities. Since this is going through JPA (you didn't mention what api you are using to access EclipseLink) you will want to be careful to manage/clear your cache appropriately so it does not use all your available memory. You will probably want to make this query read-only, and clear the cache after a few iterations using em.clear().
http://wiki.eclipse.org/Introduction_to_EclipseLink_Queries_(ELUG)#Stream_and_Cursor_Query_Results describes and has links to using streams and cursors with the native EclipseLink read queries.
It seems that CursoredStream and ScrollableCursor are meant to handle large huge collections of data objects, rather than huge objects themselves.
I'm still not sure how to retrieve Blob as a stream using EclipseLink.
I would recommend unwrapping the EntityManager to get the JDBC Connection and accessing the Blob through JDBC.
You might also try mapping the Blob to a Blob field in your object. You would only be able to access this field while the connection is active though.