I'm pretty much completely new to Spring. I've been trying to get declarative transaction management to work.
It does work, but only if I specify a data source in the transaction manager bean, as in the example:
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
We get our data source from a separate config file. So I want to leave out the data source property, we don't want it in two config files:
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
</bean>
The DataSource is available to my code. I subclassed DataSourceTransactionManager. I can get the DataSource from our configuration at run time. For testing, I dummied it up as follows:
public class MyDataSourceTransactionManager extends DataSourceTransactionManager {
public MyDataSourceTransactionManager() {
super();
BasicDataSource basicDataSource = new BasicDataSource();
basicDataSource.setDriverClassName("org.hsqldb.jdb cDriver");
basicDataSource.setUrl("jdbc:hsqldb:db_file");
basicDataSource.setUsername("sa");
basicDataSource.setPassword("");
basicDataSource.setDefaultAutoCommit(false);
super.setDataSource(basicDataSource);
}
}
This doesn't work, in the sense that my transactions are no longer atomic, each little piece commits. I tried to fix this by adding
basicDataSource.setDefaultAutoCommit(false);
as above. No luck.
I hope this isn't too obvious a question, I'm new to Spring and have no idea how to proceed, any help would be much appreciated.
Thanks,
Michael


Reply With Quote