Hi All,
I'm working on an app using Wicket, Spring and iBatis. I'm new to Wicket and Spring, but have used iBatis about 5 years ago when I did more Java programming that I do now.
I'm trying to implement Springs programmatic transaction management. From what I can tell, I think I have set everything up correctly, but am receiving an Exception "Protected method: doGetTransaction()Ljava/lang/Object" when calling the following code.I don't see what I'm doing wrong, but it must be something. Any help would be greatly appreciated!Code:TransactionStatus status = txMgr.getTransaction(def);
My entire setup is as follows:
applicationConext.xml
BRApplication.javaCode:<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>${jdbc.driver}</value> </property> <property name="url"> <value>${jdbc.url}</value> </property> <property name="username"> <value>${jdbc.username}</value> </property> <property name="password"> <value>${jdbc.password}</value> </property> <property name="maxActive" value="10"/> <property name="maxIdle" value="10"/> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="sqlMap" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation"> <value>classpath:SqlMapConfig.xml</value> </property> <property name="dataSource" ref="dataSource" /> </bean> <bean id="disService" class="com.brapp.ibatis.delegates.DisDelegate"> <property name="sqlMapClient" ref="sqlMap" /> </bean>
Homepage.javaCode:public class BRApplication extends WebApplication implements ApplicationContextAware{ private ApplicationContext ctx; private DataSourceTransactionManager transMgr; private static ISpringContextLocator CTX_LOCATOR = new ISpringContextLocator() { public ApplicationContext getSpringContext(){ return BRApplication.get().ctx; } }; @Override protected void init(){ addComponentInstantiationListener(new SpringComponentInjector( this)); super.init(); } private <T> T createProxy(Class<T> clazz){ return (T) LazyInitProxyFactory.createProxy(clazz, new SpringBeanLocator(clazz,CTX_LOCATOR)); } public Class<HomePage> getHomePage() { return HomePage.class; } public static BRApplication get() { return (BRApplication) Application.get(); } public DataSourceTransactionManager getTransactionManager(){ if(transMgr == null){ transMgr = createProxy(DataSourceTransactionManager.class); } return transMgr; } public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.ctx = applicationContext; } }
DisDelegate.javaCode:public class HomePage extends WebPage { private static final long serialVersionUID = 1L; @SpringBean (name = "disService") private DisDelegate dDelegate; public HomePage(final PageParameters parameters){ try{ Dis newD = new Dis(); newD.setDistrictName("MyDis"); newD.setDistrictInitials("MyD"); Integer myNewDstId = dDelegate.insertDis(newD); add(new Label("myNewDis","My New District Id is " + myNewDstId.toString())); }catch(Exception e){ info(e.getMessage()); } } } }
Code:public class DisDelegate implements IDisService { private PlatformTransactionManager txMgr; public int insertDis(Dis d) throws Exception { txMgr = (PlatformTransactionManager) BRApplication.get().getTransactionManager(); DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("insDis"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = txMgr.getTransaction(def); //throws exception here try{ int dstId = (Integer) sqlMap.insert("dis.insertDis", d); return dstId; }catch(Exception e){ txMgr.rollback(status); throw e; } } }


Reply With Quote