Example usage for org.hibernate Query setLockOptions

List of usage examples for org.hibernate Query setLockOptions

Introduction

In this page you can find the example usage for org.hibernate Query setLockOptions.

Prototype

Query<R> setLockOptions(LockOptions lockOptions);

Source Link

Document

Set the lock options for the query.

Usage

From source file:org.yes.cart.dao.impl.GenericDAOHibernateImpl.java

License:Apache License

/**
 * {@inheritDoc}// w  w  w  . j  a  v  a  2s  . c o  m
 */
@SuppressWarnings("unchecked")
public List<T> findByNamedQueryForUpdate(final String namedQueryName, final int timeout,
        final Object... parameters) {
    Query query = sessionFactory.getCurrentSession().getNamedQuery(namedQueryName);
    LockOptions opts = new LockOptions(LockMode.PESSIMISTIC_WRITE);
    opts.setTimeOut(timeout);
    query.setLockOptions(opts);
    if (parameters != null) {
        setQueryParameters(query, parameters);
    }
    return query.list();
}