我想给交易超时值通用。该值应设置为参量。
此代码块有效,但不是参数化的。
@Transactional(timeout=10)
@Override
public List<EntityModel> search(EntityModel model) {
List list = new ArrayList<EntityModel>();
try {
Criteria criteria = createCriteria(model);
list = criteria.list();
}
} catch (Exception e) {
}
return list;
}
这是参数设置,但不起作用。我以编程方式从数据库中给出了超时值。我利用了此页面http://neopatel.blogspot.com/2012/08/spring-query-timeout-or-transaction.html
@Transactional
@Override
public List<EntityModel> search(EntityModel model) {
List list = new ArrayList<EntityModel>();
try {
Criteria criteria = createCriteria(model);
EntityManagerFactoryInfo info = (EntityManagerFactoryInfo) entityManager.getEntityManagerFactory();
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(info.getDataSource());
transactionManager.setDefaultTimeout(PropertyUtil.getTimeoutMiliseconds());
list = criteria.list();
}
} catch (Exception e) {
}
return list;
}