|
Re: Howto call nontransactional Call in JTA Environment? [message #509913 is a reply to message #509416] |
Mon, 25 January 2010 18:42 |
|
How are you executing the out of transaction queries?
A JPA EntityManager will always execute a query that uses executeUpdate() using the transactional connection. You could try setting the "eclipselink.read-only" query hint, that may work.
You also access the ClientSession directly from the EntityManager.
You could also suspend the current JTA transaction or call a SessioBean method configured with requiresNew.
James : Wiki : Book : Blog : Twitter
|
|
|
Re: Howto call nontransactional Call in JTA Environment? [message #510017 is a reply to message #509416] |
Tue, 26 January 2010 09:00 |
Jan Junker Messages: 6 Registered: January 2010 |
Junior Member |
|
|
Hi James,
thanks for your answer, I already though noone would ever answer.
In die Toplink 9.0 code, I was using the following:
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName(this.procedureName);
DataModifyQuery query = new DataModifyQuery();
query.setCall(call);
SessionManager manager = SessionManager.getManager().getSession(sessionname);
ClientSession clientSession = serverSession.acquireClientSession();
Number success = (Number) clientSession.executeQuery(query, values);
This did the job. I was able to call commit and rollback in the stored procedure.
The call is embedded in the logic as follows: an EJB with transaction type required receives the call and does the following described in pseudo code:
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void doSomething() {
storeEntity1(); // transactional
callStoredProcedure(); // non transactional
updateEntity2(); // transacitonal
}
The problem is, that we are migrating our software to eclipselink and this stored procedure pattern is implemented all over the software, to source out the SP-calls to a separate EJB call would be quite a lot work.
Currently, I am experimenting with changing the login of the acquired session to a non-jta data source and removing the transaction controller from the connection (would be the same effect as the query hint, wouldn't it?), this works that far, that I receive a connection from the right pool, but when commiting, I always receive the ORA error saying that no commit is allowed in a subordinated session. Thus, I am still stuck.
|
|
|
Re: Howto call nontransactional Call in JTA Environment? [message #510065 is a reply to message #509416] |
Tue, 26 January 2010 13:05 |
Jan Junker Messages: 6 Registered: January 2010 |
Junior Member |
|
|
I finally found a way, but I'm quite sure it's only a hack. Doing it this way, I am able to execute a commit and rollback in the stored procedure and the other calls get handled by the JTA Transaction Manager.
DataSource dataSource = ServerServiceLocator.getInstance().getDataSource("java:/jdbc/NonJtaDS");
JNDIConnector connector = new JNDIConnector(dataSource);
connector.setLookupType(JNDIConnector.STRING_LOOKUP);
connector.setName("java:/jdbc/NonJtaDS");
DatabaseLogin login = new DatabaseLogin(new Oracle10Platform());
login.setConnector(connector);
login.setUsesExternalTransactionController(false);
login.dontUseExternalTransactionController();
ConnectionPolicy policy = new ConnectionPolicy();
policy.setExclusiveMode(ExclusiveMode.Always);
policy.setLogin(login);
policy.setPoolName(null);
SessionManager manager = SessionManager.getManager();
Server serverSession = (Server) manager.getSession("sessionname");
ClientSession clientSession = serverSession.acquireClientSession(policy);
clientSession.setExternalTransactionController(null);
try {
Number isValid = (Number) clientSession.executeQuery(query, values);
} finally {
// release the session otherwise you'll have a connection leak
clientSession.release();
}
What do you think about this?
[Updated on: Fri, 29 January 2010 08:50] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04658 seconds