The system hang while calling sqlSesssion.flushStatement()

470 Views Asked by At

I'm using some SQL query with MyBatis to update data to my Oracle db, but the system stop half way and not throwing any error.

Some forum say that it might because of connection pool size, time out problem or might be SqlSessionFactory configuration problem.

I changed all the timeout to 30 sec but still have the same problem

//my hikari datasource setup
@Bean
public HikariDataSource dataSource() {
    HikariDataSource db = new HikariDataSource();
    db.setDriverClassName(driverClassName);
    db.setJdbcUrl(url);
    db.setUsername(username);
    db.setPassword(pwd);
    db.setReadOnly(false);
    db.setMaximunPoolSize(80);
    db.setConnectionTimeout(30000);
    db.setIdleTimeout(30000);
    db.setMaxLifetime(30000);
    db.setMinimunIdle(5);
    db.setValidationTimeout(500);
    return db;
}

The section I'm calling update to my Oracle db

try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH)) {
  ItemMapper mapper = sqlSession.getMapper(ItemMapper.class);

  for (Object obj: lists) {
    //It only works fine when I'm calling insert function
    mapper.update(obj);
  }

  //After running this statement then system got stuck
  sqlSession.flushStatements();
  sqlSession.clearCache();
  sqlSession.commit();
} catch (Exception ex) {
  ex.printStackTrace();
}

This is MyBatis .xml file

<update id="update">
  UPDATE <include refid="tableName" />
  SET
    item_price = #{price},
    update_time = #{updateTime}
  WHERE id = #{id}
</update>

But the weird things is everything works fine while I'm calling insert sql statement, the system will hang or stuck at sqlSession.flushStatements(); and not throwing any errors only when I change to update sql statement.

UPDATE Even I use normal MyBatis update query also make the whole system hang but nothing happen if I use insert query..

The normal update query i execute

Obj obj = new Obj();
obj.setprice("1");
obj.setupdateTime(new Date());
mapper.update(obj);

1

There are 1 best solutions below

0
JJ___ On BEST ANSWER

This problem has been solve weirdly, seems like there is some uncommited session in somewhere although I actually restarted my server.

Just manually one click of commit button in Oracle database, then my program able to update data in database.

Please feel free to share any relevant information about some weird uncommited session of Oracle database here