hello,

I am using Spring inside an EJB (on Weblogic). Until now I was using one database only and everything was nice. The EJB had a 'transaction required' attribute. Now I have to run also a query against an archive database inside one method. As this is a SELECT to a read-only database then I don't want XA connections. So I thought I could suspend the production DB transaction while running the archive query. I am using JdbcTemplate (through JdbcOperations interface). As this is a simple query, I didn't want to create a separate bean for that. I tried to wrap the JdbcTemplate with TransactionProxyFactoryBean. I have these declarations:

Code:
  <bean id="archiveDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
      <value>jdbc/ARCH</value>
    </property>
  </bean>

  <bean id="archiveJdbcOperations" class="org.springframework.jdbc.core.JdbcTemplate">
    <constructor-arg><ref bean="archiveDataSource"/></constructor-arg>
  </bean>

  <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>

  <bean id="wrappedArchiveJdbcOperations" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="target"><ref bean="archiveJdbcOperations"/></property>
    <property name="transactionAttributes">
      <props><prop key="*">PROPAGATION_NOT_SUPPORTED</prop></props>
    </property>
  </bean>
This seems to work ok. Just a few questions:
  • is it a good idea to wrap JdbcTemplate like this?
  • although my code works, there is one exception internally - when the JdbcTemplate initializes, it uses the SQLErrorCodesFactory to get database metadata and the TransactionProxyFactoryBean is not working then yet and Weblogic throws an exception:
    Code:
    Connection has already been created in this tx context.
    How could I get around this? I know that my database is Oracle so maybe I could somehow tell my JdbcTemplate that and skip the metadata loading?


thank you,
erik