openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey" <plins...@gmail.com>
Subject Re: EntityManager.lock not working
Date Thu, 21 Feb 2008 22:18:26 GMT
> If you want pessimistic locks in OpenJPA, you'

ll need to set the openjpa.LockManager configuration setting to 'pessimistic'.

-Patrick

On Thu, Feb 21, 2008 at 2:16 PM, Patrick Linskey <plinskey@gmail.com> wrote:
> If you want pessimistic locks in OpenJPA, you'
>
>
>
>  On Thu, Feb 21, 2008 at 1:53 PM, Evan Ireland <eireland@sybase.com> wrote:
>  > Dain,
>  >
>  >  Sounds like you are wanting a pessimistic lock. The semantics
>  >  of WRITE_LOCK are defined in optimistic terms in the spec.
>  >
>  >  The JPA 2.0 expert group is looking into this. In the mean time,
>  >  only non-portable apps can get this behaviour.
>  >
>  >
>  >
>  >  > -----Original Message-----
>  >  > From: Dain Sundstrom [mailto:dain@iq80.com]
>  >  > Sent: Friday, 22 February 2008 9:50 a.m.
>  >  > To: dev@openjpa.apache.org
>  >  > Subject: EntityManager.lock not working
>  >  >
>  >  > I have a test case with two threads executing the following code:
>  >  >
>  >  >      public void run() {
>  >  >          try {
>  >  >              beginTx();
>  >  >
>  >  >              Employee david =
>  >  > entityManager.getReference(Employee.class, pk);
>  >  >              entityManager.lock(david, LockModeType.WRITE);
>  >  >              entityManager.flush();
>  >  >
>  >  >              Assert.assertTrue(entityManager.contains(david));
>  >  >
>  >  >              Assert.assertEquals(david.getId(), pk);
>  >  >              Assert.assertEquals(david.getFirstName(), "David");
>  >  >              Assert.assertEquals(david.getLastName(), "Blevins");
>  >  >              Assert.assertEquals(1000000.0, david.getSalary());
>  >  >
>  >  >              log("READ");
>  >  >
>  >  >              // wait for other threads to read
>  >  >              try {
>  >  >                  startBarrier.await(2, TimeUnit.SECONDS);
>  >  >              } catch (Exception e) {
>  >  >              }
>  >  >
>  >  >
>  >  >              log("WRITE");
>  >  >              david.setSalary(2000000);
>  >  >
>  >  >          } catch (Throwable throwable) {
>  >  >              this.throwable = throwable;
>  >  >          } finally {
>  >  >              try {
>  >  >                  commitTx();
>  >  >              } catch (Throwable throwable) {
>  >  >                  if (this.throwable == null) this.throwable =
>  >  > throwable;
>  >  >              }
>  >  >          }
>  >  >      }
>  >  >
>  >  > The first thread successfully reads the row and waits.  The
>  >  > second throws an exception at the entityManager.flush()
>  >  > command after the write lock.  I would assume that when I say
>  >  > "give me a write lock"
>  >  > OpenJPA would "give me a write lock".  Is there anyway to get
>  >  > write lock in my application for single rows without having
>  >  > to switch everything to SERIALIZABLE?
>  >  >
>  >  > -dain
>  >  >
>  >
>  >
>
>
>
>  --
>  Patrick Linskey
>  202 669 5907
>



-- 
Patrick Linskey
202 669 5907

Mime
View raw message