【发布时间】:2017-11-20 20:03:17
【问题描述】:
我为长时间运行的存储过程调用创建了一个异步服务。一切正常,但是在事务注释的超时属性中给出的指定值之后事务没有超时。代码的结构如下所示(不是真实的......只是骨架......忽略语义/语法)
//asynchronous service
@override
@async("myCustomTaskExecutor")
@Transactional(rollbackfor=Exception.class,timeout=600)
public void serviceMethod(){
//repository method is invoked.
repository.callStoredProcedure();
}
//Repository method in the Repository class
@Transactional(rollbackfor=Exception.class,timeout=600)
public void callStoredProcedure(){
//Stored procedure is called from the private method using hibernate doWork implementation.
privateCallmethod();
}
private void privateCallmethod() throws ApplicationException{
Session session = null;
try{
session = entityManager.unwrap(Session.class);
session.doWork(new Work(){
@Override
public void execute(Connection connection) throws SQLException {
OracleCallableStatement statement =null;
try{
//using hibernate 4.x and ref cursors are used...so went on with this approach..
//suggest if there is some better approach.
String sqlString =“{begin storProcName(?,?)}”;
statement = connection.prepareCall(sqlString);
statement.setInt(1,5);
statement.setString(2,“userName5”);
statement.executeUpdate();
}
catch(Exception e){
throw RunTimeException(e.getMessage);
}
finally{
if(statement != null)
statement.close();
}
}
}
});
}
catch(Exception e){
throw ApplicationException(e.getMessage);
}
//Not using Final block to close the session.Is it an issue ?
}
存储过程端发生延迟(Thread.sleep(700) 未使用)但事务未超时...
问题:
- 我想
@Transactional仅在服务方法上就足够了...对使用@Transactional注释的正确方法提供一点见解 用于此代码设置。 -
@Transactional是否适用于doWork接口实现中的 JDBC 调用...这是什么问题? - 有些文章建议在
CallableStatement中使用oracle.jdbc.readTimeout或setQueryTimeout...这是实现此目的的正确方法吗? - 请指出错误并说明原因
【问题讨论】:
标签: spring hibernate asynchronous jdbc transactions