1

MyBatis 3 で Spring 4 を使用しています。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: 

これが私のマッパーファイルでの私の定義です

<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>

データベースで call 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);
    }
4

3 に答える 3

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>
于 2015-08-11T15:52:42.743 に答える
0

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>
于 2017-12-20T15:48:24.527 に答える