This seems to be working but want to make sure it's safe (or the wrong approach.)
Relevant portion of spring config:
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="oracleDS"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="oracleDS"/>
<property name="typeAliasesPackage" value="com.ncs.domain"/>
<property name="typeHandlersPackage" value="com.ncs.typehandler"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.ncs.mapper"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
<bean id="batchSqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
<constructor-arg index="1" value="BATCH" />
</bean>
<bean id="batchService" class="com.ncs.service.BatchService">
<property name="sqlSession" ref="batchSqlSession"/>
</bean>
My 'regular' service classes uses the mappers directly myMapper.whatever.
My batch calls are made in the batchService... which looks like...
private SqlSession sqlSession;
public void setSqlSession(SqlSession sqlSession) {
this.sqlSession = sqlSession;
}
public void doSomething() {
EQMapper eqMapper = sqlSession.getMapper(EQMapper.class);
eqMapper.doSomething(...)
}
I'm just not sure it's ok to use the same sqlSessionFactory instance for both the standard mappers and then again in the SqlSessionTemplate used by the batchService (with it set to BATCH) ?
Is it better to make a whole new instance of SqlSessionFactory in my config (using the same datasource instance.)
Thanks