春季交易超时值以编程方式

时间:2019-05-20 06:22:46

标签: java spring transactions timeout

我想给交易超时值通用。该值应设置为参量。

此代码块有效,但不是参数化的。

@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;
}

0 个答案:

没有答案