“Session closed” error when trying to get a blob from DB using getBinaryStream()
I'm using Hibernate 3.1 and Oracle 10 DB. The blob is defined as @Lob @Basic @Column in the Hibernate entity which corresponds to the relevant DB table. The error -java.sql.SQLException: Closed Connection- seem to appear once in while, not in every attempt to get the blob from the DB. This seems like a hibernate fetching issue, so I thought of specifying the type of fetch to be used - EAGER seems right in this case -but coudln't find any way to specify type of fetching for @Column type of object (there is a way to do that for collections / "one to many" relationships etc)
Would appreciate your help, thanks.
I've recently implemented a hibernate system on top of a Oracle 11g db that uses blobs. There isn't any real magic to it.
The standard cause of 'Session closed' hibernate errors is (not to point out the obvious) that the session that your entity is attached to really is closed.
Make a point of working out exactly where and when the session is being opened and closed. This may not be completely obvious if you are using AOP or a spring to manage this for you.
In addition I'm pretty sure you need an open transaction, or at least an db connection with autocommit turned off.
Is this against an Oracle database?
I've had to resort to user data types in Hibernate to get this to work, but that was using Hibernate 3.0 against an Oracle 9 db.
See http://www.hibernate.org/56.html for a long discussion about this topic (including user data types).
If you want to specify the fetching strategy use:
@Basic(fetch = FetchType.LAZY)
for your member.
Setting the system property hibernate.jdbc.use_streams_for_binary=true might help.