Hi,

if you set "useAutoCommit=1", OJB set the connection autoCommit attribute to 'false' when PB-tx demarcation is used. After the PB-tx the autoCommit attribute is reset to 'true'.
http://db.apache.org/ojb/docu/guides/repository.html#useAutoCommit

Everything done between PB.begin... and PB.commit... will use the same connection with autoCommit 'false', thus on rollback nothing will be written to DB.

regards,
Armin



Guillaume Laforge wrote:
Hi all,

I'm having some issues with the PersistenceBroker.

I've got a one-to-many relationship, say a sentence, which has got
localized labels (1 sentence <-> several multilingual labels).

I want to store a new sentence with a new set of labels.
But I want to do that in a single transaction, so that if something
fails, I can rollback everything.

So, somewhere in my code, I'm doing a broker.beginTransaction().
I store my sentence. I create some labels a bit further and store them.
And later, broker.commitTransaction().
And in case something fails, I'm rollback-ing the transaction in some
try catch finally surrounding my code.

If autocommit is true, then my sentences and labels are stored... but,
unfortunately, if something goes wrong, OJB won't rollback anything.
So autocommit to true is not a good option for me since I want a real
transaction (I also tried setting autocommit on the broker object
itself but that wasn't any better).

If I set useAutoCommit="2" in my jdbc-connection-descriptor, I store
my sentence, but just after I see a weird message in the logs:

accesslayer.ConnectionManagerImpl  - Release connection: connection is
in local transaction, missing 'localCommit' or 'localRollback' call -
try to rollback the connection

And then, when I try to store the first label, I get an exception:

org.apache.ojb.broker.KeyConstraintViolatedException: SQL failure
while insert object data for class com.foo.bar.Xxxx, PK of the given
object is [ id=201], object was xxxx, exception message is [ORA-02291:
integrity constraint  (AE6.SYS_C001821) violated - parent key not
found.

The message basically means that it can't find the sentence primary
key that the label is referencing (foreign key).

Background: I'm using OJB 1.0.3 and Oracle 9i with the thin driver.

So, I was wondering how I could store a new sentence and label in on
transaction and be able to rollback everything if I so desire?


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to