[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] How to disable auto-commit in EclipseLink
|
Hi Andrei,
thank you for clarifying my issue and for pointing out the need of a
transaction controller
in order to get full and safe control of the transaction which shares
a connection.
Because I have some (rather non-technical) difficulties changing the
current transaction concept in my current project for the short term
I am thinking about a workaround which will help me out till our
transaction system supports JTA:
What about just ignoring the setAutoCommit(true) call from EclipseLink
(I am always using a custom Connection wrapper object so I simply
would not delegate the call to the underlying wrapped Connection)?
It's guaranteed that the outside transaction manager will invoke a
commit()/rollback() on the Connection right after invoking
commit()/rollback() on the EntityManager's transaction.
Do you think that this will do the job (as a workaround) and not break
anything (wrong data)?
If not, in which cases this workaround will not work?
Thank you very much and best regards,
Patric
Zitat von Andrei Ilitchev <andrei.ilitchev@xxxxxxxxxx>:
Answers inline.
On 12/16/2010 6:32 AM, patric@xxxxxxxxxxx wrote:
After tracing and looking through the source code I think that this
issue is even more crucial:
EclipseLink will only enable auto-commit after a rollback() or commit()
of a transaction:
Please have a look at DatabaseAccessor.java:
basicBeginTransaction() will disable auto-commit()
basicCommitTransaction() will enable auto-commit()
basicRollbackTransaction() will also enable auto-commit()
This means that the result in the database of some JPA operations may
differ if a tranaction has been rollbacked or committed before.
The result in the db in the same no matter what has happened before
beginTransaction.
Why has it been implemented that way?
basicBegin/Commit/RollbackTransaction methods are used only in case
connections are not managed.
Eclipselink acquires connection from connection pool assuming it has
full control over it. It doesn't assume that connection may be in
use and in the middle of transaction.
In the end of transaction auto-commit is set to true because some
Eclipselink configurations support writing without transactions
(DatabaseSession).
Is it an intentional behaviour?
Yes
Zitat von patric@xxxxxxxxxxx:
Hi,
I just saw that EclipseLink tries to enable the autocommit
functionality on the Connection object in some cases.
How can I disable that?
Because I am sharing the Connection which is used by EclipseLink with
some other transaction controller an auto-commit simply break the
transaction concept.
You can't do that. Instead tell Eclipselink that you use external
transaction controller (in persistence.xml or pass to createEMF):
property "eclipselink.target-server" -> "MyTransactionController"
where:
class MyTransactionController extends
org.eclipse.persistence.transaction.JTATransactionController {
public MyTransactionController() {
super();
this.transactionManager = new MyTransactionManager();
}
}
use it together with your data source, indicate that external
transaction controller is used:
public class Customizer implements SessionCustomizer {
public void customize(Session session) throws SQLException {
CustomServerPlatform platform = new
CustomServerPlatform(session);
platform.setExternalTransactionControllerClass(JTATransactionController.class);
session.setServerPlatform(platform);
MyDataSource ds = new MyDataSource();
ds.setURL(session.getLogin().getConnectionString());
session.getLogin().setConnector(new JNDIConnector(ds));
session.getLogin().useExternalConnectionPooling();
session.getLogin().useExternalTransactionController();
}
}
In you app. begin JTA transaction, obtain connection from the data
source, do whatever jdbc you need to do,
then createEntityManager, join it to the transaction
(em.joinTransaction()), do whatever jpa you need to do;
then commit JTA transaction.
If there's no such functionality - is it safe to intercept
EclipseLink's setAutoCommit(true) invocation by my Connection wrapper?
Thank you and best regards,
Patric
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users