我正在使用Spring 4和MyBatis 3.我在Oracle 11g中调用一个存储过程,它从一个临时表中处理一堆数据并将数据插入到其他几个表中。存储过程调用其中的commit。但是没有任何东西被持久化,没有例外或警告,除此之外,日志中没有任何内容。
11:59:48.297 DEBUG BaseJdbcLogger.debug - ==> Preparing: {call PKG_DIRECTORY.sp_process_staged_data}
11:59:48.318 DEBUG BaseJdbcLogger.debug - ==> Parameters:
这是我在mapper文件中的定义
<insert id="processDirectory" statementType="CALLABLE">
{call PKG_DIRECTORY.sp_process_staged_data}
</insert>
这是界面
public interface StagedDataMapper {
@Async
void processDirectory();
List<StageDirectory> getStagedDirectory(long institutionId);
List<StageAppointment> getStagedAppointment(long institutionId);
}
我尝试过插入,更新,选择,没有任何作用。
更新:
我发现了一个小小的错误,但它没有纠正这个问题。
更新了映射文件
<select id="processDirectory" statementType="CALLABLE">
{call PKG_DIRECTORY.sp_process_staged_data()}
</select>
我可以直接在数据库上运行PKG_DIRECTORY.sp_process_staged_data(),它运行正常。
更新2:
这是我的MyBatis配置:
@Configuration
public class PersistenceConfig {
@Autowired
Environment environment;
@Bean(name = "datasource")
public ComboPooledDataSource dataSource() throws PropertyVetoException {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setDriverClass(environment.getRequiredProperty("c3p0.driver"));
dataSource.setJdbcUrl(environment.getRequiredProperty("c3p0.url"));
dataSource.setUser(environment.getRequiredProperty("c3p0.user"));
dataSource.setPassword(environment.getRequiredProperty("c3p0.password"));
dataSource.setInitialPoolSize(environment.getRequiredProperty("c3p0.initialPoolSize", Integer.class));
dataSource.setMaxPoolSize(environment.getRequiredProperty("c3p0.maxPoolSize", Integer.class));
dataSource.setMinPoolSize(environment.getRequiredProperty("c3p0.minPoolSize", Integer.class));
dataSource.setAcquireIncrement(environment.getRequiredProperty("c3p0.acquireIncrement", Integer.class));
dataSource.setMaxStatements(environment.getRequiredProperty("c3p0.maxStatements", Integer.class));
dataSource.setMaxIdleTime(environment.getRequiredProperty("c3p0.maxIdleTime", Integer.class));
return dataSource;
}
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setTypeAliasesPackage("org.something.core.domain");
return sessionFactory.getObject();
}
@Bean(name = "transactionManager")
public DataSourceTransactionManager dataSourceTransactionManager() throws PropertyVetoException{
return new DataSourceTransactionManager(dataSource());
}
}
我的映射器
<insert id="processDirectory" statementType="CALLABLE">
{CALL PKG_DIRECTORY.SP_PROCESS_STAGED_DATA()}
</insert>
更新3:
我做了另一次尝试,但仍然没有运气。考虑放弃MyBatis,这已成为一个问题。
稍微更改了我的持久性配置
public class PersistenceConfig {
@Autowired
Environment environment;
@Bean(name = "datasource")
public ComboPooledDataSource dataSource() throws PropertyVetoException {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setDriverClass(environment.getRequiredProperty("c3p0.driver"));
dataSource.setJdbcUrl(environment.getRequiredProperty("c3p0.url"));
dataSource.setUser(environment.getRequiredProperty("c3p0.user"));
dataSource.setPassword(environment.getRequiredProperty("c3p0.password"));
dataSource.setInitialPoolSize(environment.getRequiredProperty("c3p0.initialPoolSize", Integer.class));
dataSource.setMaxPoolSize(environment.getRequiredProperty("c3p0.maxPoolSize", Integer.class));
dataSource.setMinPoolSize(environment.getRequiredProperty("c3p0.minPoolSize", Integer.class));
dataSource.setAcquireIncrement(environment.getRequiredProperty("c3p0.acquireIncrement", Integer.class));
dataSource.setMaxStatements(environment.getRequiredProperty("c3p0.maxStatements", Integer.class));
dataSource.setMaxIdleTime(environment.getRequiredProperty("c3p0.maxIdleTime", Integer.class));
return dataSource;
}
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setTypeAliasesPackage("org.something.core.domain");
sessionFactory.setTransactionFactory(springManagedTransactionFactory());
return sessionFactory.getObject();
}
@Bean(name = "transactionManager")
public DataSourceTransactionManager dataSourceTransactionManager() throws PropertyVetoException{
return new DataSourceTransactionManager(dataSource());
}
@Bean
public SpringManagedTransactionFactory springManagedTransactionFactory() {
return new SpringManagedTransactionFactory();
}
}
将mybatis版本从3.3.0下调至3.2.8,将mybatis-spring从1.2.3下调至1.2.2。
Mapper看起来像这样:
public interface StagedDataMapper {
void processDirectory();
List<StageDirectory> getStagedDirectory(long institutionId);
List<StageAppointment> getStagedAppointment(long institutionId);
}
控制器方法
@Transactional
@RequestMapping(value = "/directory/process", method = RequestMethod.POST)
public ResponseEntity processStagedDirectory() {
stagedDataMapper.processDirectory();
return new ResponseEntity(HttpStatus.ACCEPTED);
}
答案 0 :(得分:0)
不确定以下内容是什么
<insert id="processDirectory" statementType="CALLABLE">
<![CDATA[{ CALL PKG_DIRECTORY.SP_PROCESS_STAGED_DATA() }]]>
</insert>
这不是
<insert id="processDirectory" statementType="CALLABLE">
{ CALL PKG_DIRECTORY.SP_PROCESS_STAGED_DATA() }
</insert>
答案 1 :(得分:0)
MyBatis似乎回滚所有非显式UPDATE或DELETE的查询。
对我来说,解决方案是将属性 commitRequired =&#34; true&#34; 添加到。不知道这是如何转化为你的情况,但似乎是同样的问题。
来自LSC-Project(使用MyBatis)的例子:
<transactionManager type="JDBC" commitRequired="true">
<dataSource type="SIMPLE">
<property value="${driver}" name="JDBC.Driver" />
<property value="${url}" name="JDBC.ConnectionURL" />
<property value="${username}" name="JDBC.Username"/>
<property value="${password}" name="JDBC.Password"/>
<property value="15" name="Pool.MaximumActiveConnections"/>
<property value="15" name="Pool.MaximumIdleConnections"/>
<property value="1000" name="Pool.MaximumWait"/>
</dataSource>
</transactionManager>
答案 2 :(得分:0)
一个很老的问题,但是明显的答案不存在。 只是改变
<select ... </select>;
到
<update ... </update>
这表明MyBatis尊重交易行为。