TopLinkTransactionManager unable to expose a TopLink transaction to JDBC access code [SPR-4382] #9061
Labels
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
Marc Ludwig opened SPR-4382 and commented
(see http://forum.springframework.org/showthread.php?t=48968 for further info)
In Spring docs it states:
"TopLinkTransactionManager is capable of exposing a TopLink transaction to JDBC access code that accesses
the same JDBC DataSource, provided that TopLink works with JDBC in the backend and is thus able to expose
the underlying JDBC Connection. The DataSource to expose the transactions for needs to be specified
explicitly; it won't be autodetected."
In order to generate and call some anonymous PL/SQL blocks (to deal with Oracle associative arrays used in legacy code) we are using JdbcDaoSupport.
The rest of our app used TopLinkDaoSupport.
I saw in the documentation that Toplink transaction can be exposed to JDBC, but I think that this will never occur due to the SessionFactory creating a Proxy aound the Session, whilst checks within the ToplinkTransactionManager to retrieve the JDBCConnection assume a ClientSession.
Stepping through doBegin in TopLinkTransactionManager I think shows that a jdbcConnection will never be retrieved from a Writeable Toplink Client Session.
TopLinkTransactionManager.doBegin
Code:
if (!definition.isReadOnly()) {
logger.debug("Creating managed TopLink Session with active UnitOfWork for read-write transaction");
session = getSessionFactory().createManagedClientSession();
}
ServerSessionFactory.createManagedClientSession (in AbstractSessionFactory)
Code:
logger.debug("Creating managed TopLink client Session");
return (Session) Proxy.newProxyInstance(
getClass().getClassLoader(),
new Class[] {Session.class},
new ManagedClientInvocationHandler(createClientSession()));
But later in TopLinkTransactionManager.doBegin it calls getJdbcConnection
Code:
if (!(session instanceof oracle.toplink.publicinterface.Session)) {
if (logger.isDebugEnabled()) {
logger.debug("TopLink Session [" + session +"] does not derive from [oracle.toplink.publicinterface.Session]");
}
return null;
Unless I'm mistaken (a big risk!), a writeable Toplink Session will never be able to provide the JDBC Connection to the JdbcDaoSupport, as it's an instance of Proxy (notSession).
Is this expected behaviour, meaning that the ToplinkTransactionManager.getJdbcConnection should be overridden to deal with the Proxy instance, or is it a bug within the Spring-Toplink Integration layer.
As always, many thanks for investigating.
Marc
Affects: 2.0.8, 2.5.1
Backported to: 2.0.9
The text was updated successfully, but these errors were encountered: