org.hibernate.HibernateException: Unable to access lob stream org.hibernate.HibernateException: Unable to access lob stream oracle oracle

org.hibernate.HibernateException: Unable to access lob stream


Try adding @Transactional over the service method where you are trying to access lob field object. It worked for me.


I believe I had this one before.

When a large object (CLOB, BLOB) is loaded from Oracle, it is returned as a reference to a stream. If the record is mapped to hibernate and the session is closed after the object is loaded (so the object becomes detached) the java field blob is mapped to is not containing the data yet; so when you're trying to save it back it cannot work with it because the clob/blob stream is gone.

For a start, try to keep loading and saving within the same session.

If I remember right, another workaround would be to "touch" the clob/bloc java field while the loading session is still open. Then the data will be read from the DB. But it is painfully inefficient (it is LOB for a reason, i.e. it is big).

Yet another option is to split the small data and lobs into two different tables, and load lobs only when needed.

Hope that helps you with the direction.


My pure guess is that you have some field that is very large, so it is mapped to sql lob. Mapping itself is incorrect, I suspect. But it only happens when you try to save entity with nonnull value. Try to save all your entities with nonnull fields in app one by one. This will isolate the problem.