Package javax.persistence

Examples of javax.persistence.EntityManager.lock()


    em.persist( lock );
    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.getReference( UnversionedLock.class, lock.getId() );
    em.lock( lock, LockModeType.READ );
    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.getReference( UnversionedLock.class, lock.getId() );
    em.remove( lock );
View Full Code Here


        final Object entity2 = em2.find(entityClass, oid);
        final long timeout = 1000;
        try {
            Map<String,Object> hint = new HashMap<String, Object>();
            hint.put("javax.persistence.lock.timeout", timeout);
            em2.lock(entity2, LockModeType.PESSIMISTIC_WRITE, hint);
            fail("Expected " + PessimisticLockException.class.getName());
        } catch (Throwable t) {
           assertError(t, PessimisticLockException.class);
        }
        assertTrue(em2.getTransaction().isActive());
View Full Code Here

  public void lock(Object entity, LockModeType lockMode)
  {
    EntityManager em = getCurrent();
   
    if (em != null) {
      em.lock(entity, lockMode);
      return;
    }
   
    em = createEntityManager();
   
View Full Code Here

    }
   
    em = createEntityManager();
   
    try {
      em.lock(entity, lockMode);
    } finally {
      freeEntityManager(em);
    }
  }
View Full Code Here

                   Map<String, Object> properties)
  {
    EntityManager em = getCurrent();
   
    if (em != null) {
      em.lock(entity, lockMode, properties);
      return;
    }
   
    em = createEntityManager();
   
View Full Code Here

    }
   
    em = createEntityManager();
   
    try {
      em.lock(entity, lockMode, properties);
    } finally {
      freeEntityManager(em);
    }
  }
View Full Code Here

    em.persist( lock );
    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.getReference( Lock.class, lock.getId() );
    em.lock( lock, LockModeType.READ );
    lock.setName( "surname" );
    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.find( Lock.class, lock.getId() );
View Full Code Here

    }
    catch (TransactionRequiredException e) {
      //success
    }
    try {
      em.lock( book, LockModeType.READ );
      fail( "lock has to be inside a Tx" );
    }
    catch (TransactionRequiredException e) {
      //success
    }
View Full Code Here

    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.getReference( Lock.class, lock.getId() );
    Integer version = lock.getVersion();
    em.lock( lock, LockModeType.WRITE );
    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.getReference( Lock.class, lock.getId() );
    try {
View Full Code Here

    em.persist( lock );
    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.getReference( UnversionedLock.class, lock.getId() );
    em.lock( lock, LockModeType.READ );
    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.getReference( UnversionedLock.class, lock.getId() );
    em.remove( lock );
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.