views:

82

answers:

2

can i create multiple connections during one transaction and perform commit on them provided the connection are taken from data source in weblogic. ??? please help

+1  A: 

You mean from different datasource?

Of course you can. That's what JTA are for.

Just make sure that involved datasources' driver are XA-awared.


Edited I got what you mean.

The application I developed has such feature. Assume you have some basic flow control or handler structure for your request processing routine, you can always start a new transaction just for the error handling part, commit that new tranasction, and rollback the original one.

With Spring + Declarative transaction control you need to have a transaction declared around the error handling routine, with a REQUIRES_NEW propagation policy

Adrian Shum
hi Adrian... if my datasource is not XA-awared.. then will there be any problem.
Mrityunjay
Well yes ... unless you have some other way to perform two-phase commit across the "enlisted" data sources for a transaction.
Stephen C
i mean.. suppose i am using hibernate and data source as connection provider.. but for one case i need to rollback the complete execution.. but want to insert into one table with the time .. and some details... i thought to use connection from data source and use the simple process to insert into the table using PreparedStatement... will there be any problem regarding connection..
Mrityunjay
Do you mean an autonomous transaction to record the failure before rolling back?
Alex Poole
@Mrityunjay: I don't see the difference between your case and some very normal case of having multiple insert/update/delete within the same transaction
Adrian Shum
@Alex yes. this is what i want to achieve..just record the failure before complete rollback..
Mrityunjay
A: 

Based on the comment that you want, effectively, an autonomous transaction to log a failure, you can either use a second connection from your datasource and commit that while rolling back the original failed one (which doesn't require XA; the wording in your question suggests you want to commit both connections simultaneously); or if you can use an actual autonomous transaction to handle the logging inside your original connection before rolling back. This is probably simpler and cleaner, particularly if your failure is really coming from a package call anyway as it can be dealt with as the failure occurs rather than having the client worry about it. In outline:

PROCEDURE log_failure(...)
IS
    PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
    insert ...
    commit;
END log_failure;
Alex Poole