Example usage for javax.persistence PessimisticLockScope EXTENDED

List of usage examples for javax.persistence PessimisticLockScope EXTENDED

Introduction

In this page you can find the example usage for javax.persistence PessimisticLockScope EXTENDED.

Prototype

PessimisticLockScope EXTENDED

To view the source code for javax.persistence PessimisticLockScope EXTENDED.

Click Source Link

Document

In addition to the behavior for PessimisticLockScope.NORMAL, element collections and relationships owned by the entity that are contained in join tables will be locked if the javax.persistence.lock.scope property is specified with a value of PessimisticLockScope.EXTENDED.

Usage

From source file:com.vladmihalcea.HibernateCascadeLockComponentTest.java

@Test
public void test() {

    final Long parentId = cleanAndSaveParent();

    transactionTemplate.execute(new TransactionCallback<Void>() {
        @Override//from   w ww. j  a v a  2 s . c o  m
        public Void doInTransaction(TransactionStatus transactionStatus) {
            Post post = entityManager.find(Post.class, parentId);
            entityManager.lock(post, LockModeType.PESSIMISTIC_WRITE, Collections
                    .singletonMap("javax.persistence.lock.scope", (Object) PessimisticLockScope.EXTENDED));
            return null;
        }
    });
}