PDA

View Full Version : Transaction Setup for Ibatis/HSQLDB



bincbom
Jan 19th, 2006, 12:48 PM
Hello Everyone!

We are building a data model using Spring DAO, and this model is based on the Petclinic sample application in Spring 1.1.5 (ibatis flavor).

Everything is working. But I'm wondering about transactions, and what I have to do to set them up correctly. Here is our datasource/txn manager configuration:

<beans>
<bean id="dataSource" class="com.ibatis.common.jdbc.SimpleDataSource">
<constructor-arg>
<map>
<entry key="JDBC.Driver"><value>org.hsqldb.jdbcDriver</value></entry>
<entry key="JDBC.ConnectionURL"><value>jdbc:hsqldb:hsql://10.250.1.23</value></entry>
<entry key="JDBC.Username"><value>sa</value></entry>
<entry key="JDBC.Password"><value></value></entry>
<entry key="JDBC.DefaultAutoCommit"><value>true</value></entry>
</map>
</constructor-arg>
</bean>

<!-- Transaction manager for a single JDBC DataSource -->
<!-- (see dataAccessContext-jta.xml for an alternative) -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTran sactionManager">
<property name="dataSource"><ref local="dataSource"/></property>
</bean>

<!-- SqlMap setup for iBATIS Database Layer -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactory Bean">
<property name="configLocation"><value>conf/sql-map-config.xml</value></property>
<property name="dataSource"><ref local="dataSource"/></property>
</bean>

Does this current arrangement provide transactions or not? Or do I need to set up a transaction proxy and specify which methods actually get transactions? How can I tell whether transactions are actually being used?

Please advise.

Thanks in advance,
craig vanderborgh
voxware incorporated

duffymo
Jan 20th, 2006, 07:44 AM
Hello Everyone!

We are building a data model using Spring DAO, and this model is based on the Petclinic sample application in Spring 1.1.5 (ibatis flavor).

Everything is working. But I'm wondering about transactions, and what I have to do to set them up correctly. Here is our datasource/txn manager configuration:

<beans>
<bean id="dataSource" class="com.ibatis.common.jdbc.SimpleDataSource">
<constructor-arg>
<map>
<entry key="JDBC.Driver"><value>org.hsqldb.jdbcDriver</value></entry>
<entry key="JDBC.ConnectionURL"><value>jdbc:hsqldb:hsql://10.250.1.23</value></entry>
<entry key="JDBC.Username"><value>sa</value></entry>
<entry key="JDBC.Password"><value></value></entry>
<entry key="JDBC.DefaultAutoCommit"><value>true</value></entry>
</map>
</constructor-arg>
</bean>

<!-- Transaction manager for a single JDBC DataSource -->
<!-- (see dataAccessContext-jta.xml for an alternative) -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTran sactionManager">
<property name="dataSource"><ref local="dataSource"/></property>
</bean>

<!-- SqlMap setup for iBATIS Database Layer -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactory Bean">
<property name="configLocation"><value>conf/sql-map-config.xml</value></property>
<property name="dataSource"><ref local="dataSource"/></property>
</bean>

Does this current arrangement provide transactions or not? Or do I need to set up a transaction proxy and specify which methods actually get transactions? How can I tell whether transactions are actually being used?

Please advise.

Thanks in advance,
craig vanderborgh
voxware incorporated


Hi Craig,

I think you have to set up a transaction proxy and specify the propagation requirements. You'll need more stuff in your context XML. These should not be on the DAO classes themselves, rather on the service classes that use the DAOs.

If you're unit testing DAOs, there's no need for the transaction proxy. I had a recent thread in the Data Access forum that details my struggles in excrutiating detail.

You can tell they're being used if you turn on logging at the DEBUG level. You'll see the rollbacks and commits that way.

%