Leandro
Leandro

Reputation: 950

Error Saving and getting blob from database SQL oracle

I'm trying to save a CLOB into the database and recovering it, but I'm getting an SQLException:

Caused by: java.sql.SQLException: Lob read/write functions called while another read/write is in progress: getBytes()
 at oracle.jdbc.driver.T4CConnection.getBytes(T4CConnection.java:2427)
 at oracle.sql.BLOB.getBytes(BLOB.java:348)
 at oracle.jdbc.driver.OracleBlobInputStream.needBytes(OracleBlobInputStream.java:181)

I figured that the problem is when I tried to get the CLOB, because it's still saving. If the CLOB is small it works fine, but when the CLOB is a little bigger it fails.

Sorry about my english and thanks

EDIT:

The annotation is:

@Lob
@Column(nullable = false)
private String body;

The save method

emailRepository.save(email); 

Upvotes: 5

Views: 4271

Answers (2)

zibi
zibi

Reputation: 3313

I encountered a similar problem in one of the projects, setting

updatable = false

fixed the issue for me.

Example:

@Lob
@Column(name = "CONTENT", updatable = false)
Blob content;

Hibernate somehow tries to re-save the content, even when it was not changed.

Upvotes: 3

groschan
groschan

Reputation: 66

Setting the hibernate property

<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>

sorved the problem for me.

Setting the lobCreator for SessionFactory to NonContextualLobCreator is probably a better solution (not tried yet).

However I'm not sure what causes this error.

Upvotes: 2

Related Questions