[英]MyBatis Not Persisting Stored Procedure Call
我將Spring 4與MyBatis 3一起使用。我正在Oracle 11g中調用一個存儲過程,該存儲過程處理臨時表中的一堆數據並將該數據插入其他幾個表中。 存儲過程調用在其中進行提交。 但是,沒有任何內容可以保留,沒有異常或警告,除了此以外,日志中沒有任何內容。
11:59:48.297 DEBUG BaseJdbcLogger.debug - ==> Preparing: {call PKG_DIRECTORY.sp_process_staged_data}
11:59:48.318 DEBUG BaseJdbcLogger.debug - ==> Parameters:
這是我在映射器文件中的定義
<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。
映射器如下所示:
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);
}
不知道是什么,但是以下工作
<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>
MyBatis似乎回滾所有不是顯式UPDATE或DELETE的查詢。
對我來說,解決方案是將屬性commitRequired =“ true”添加到中。 不知道如何將其轉換為您的情況,但似乎是同樣的問題。
來自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>
這是一個很老的問題,但是沒有明顯的答案。 只是改變
<select ... </select>;
至
<update ... </update>
這標志着MyBatis尊重交易行為。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.