wood burning stoves 2.0*
The moose likes JDBC and the fly likes Java Transaction API And BLOB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Java Transaction API And BLOB" Watch "Java Transaction API And BLOB" New topic
Author

Java Transaction API And BLOB

Mattias Malmgren
Greenhorn

Joined: Dec 01, 2011
Posts: 2
Is it possible to insert a blob into Oracle database as part of a javax.transaction.UserTransaction?

I am not sure I read the manuals right. From:

http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Transaction4.html#63068 "However, the Java EE transaction manager does have one limitation: it does not support nested transactions. In other words, it cannot start a transaction for an instance until the preceding transaction has ended."

And from: http://docs.oracle.com/cd/B10500_01/appdev.920/a96591/adl05adv.htm#98415 "Modifying an internal LOB's value through the LOB locator using DBMS_LOB, OCI, or SQL INSERT or UPDATE statements changes the locator from a read consistent locator to an updated locator. Further, the INSERT or UPDATE statement automatically starts a transaction and locks the row. Once this has occurred, the locator may not be used outside the current transaction to modify the LOB value. In other words, LOB locators that are used to write data cannot span transactions"

Is my conclusion right that XA (JTA UserTransaction) can not involve insert of a BLOB? When I try to test my program code I get the ORA-error: ORA-22990
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

I don't think the sources you cited support your conclusion. The ORA-22990 simply means that you've ended your transaction too early. Though I don't use XA, I think it leaves it on you when a transaction commits/rolls back. XA just coordinates the transaction among different systems.

I'd suggest to check whether you don't have an autocommit set on your connection. That would produce the ORA-22990 error even if you didn't use distributed transactions. (Amazingly, the autocommit is on by default in JDBC.)
Mattias Malmgren
Greenhorn

Joined: Dec 01, 2011
Posts: 2


I thought about autocommit too. Doesn't seam to help though. If I don't use blobOutputStream.flush(); the blob is never saved to the database. The program runs fine if I take the tx.begin(); and tx.commit(); away.



Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

Quick search through Oracle9i Application Developer's Guide - Large Objects (LOBs) does not yield anything about distributed transactions. I don't think it is generally impossible to modify LOBs in distributed environments, but maybe there is some incompatibility in your specific environment. Could you use sql trace to see when the commits happen and align them with commands being run on your application?

Reading the guide mentioned above (in version corresponding to your database) might be useful too. Maybe some scenario involving temporary BLOBs could help you sail through in your environment.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Transaction API And BLOB
 
Similar Threads
Problem inserting Blob into Oracle DB
how to create BLOB and CLOB data
java.io.ioException
How to update string to Oracle Clob
Problem updating BLOB