I have faced an error in saving a
record in a table
"ORA-01465: invalid hex number" While using BLOB in hibernate:
I have to convert a data object to a BLOB and save it in a data base.
I was facing an error called "ORA-01465: invalid hex number " whenever i tried to save the data row with the blob data in one of the column.
Error created code piece.:
try {
ByteArrayOutputStream ba = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(ba);
os.writeObject(object);
os.flush();
try {
message = oracle.sql.BLOB.createTemporary(null, false, oracle.sql.BLOB.DURATION_SESSION);
message.setBytes(1, ba.toByteArray());
System.out.println("This is the Blob message " + message);
} catch (SQLException e) {
LOG.error("Error while converting Byte array to BLOB ", e);
}
os.close();
} catch (IOException ioe) {
// ioe.printStackTrace();
}
}
Later I found in one of the site that there is a class called BlobImpl in Hibernate. I used following code to resolve the issue.
Solution:
try {
ByteArrayOutputStream ba = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(ba);
os.writeObject(object);
os.flush();
// message = oracle.sql.BLOB.empty_lob();
// message.setBytes(1, ba.toByteArray());
BlobImpl blobImpl = new BlobImpl( ba.toByteArray() );
message = blobImpl;
// System.out.println("This is the Blob message " + message);
os.close();
} catch (IOException ioe) {
// ioe.printStackTrace();
}
Nice Info and good to share ur experiance.. Will get useful to many when they encounter such a situ.. :)
ReplyDeleteNice Info and good to share ur experiance..
ReplyDeletebuttttt... not won't to meet this website people