Does that make all locks pessimistic? I wouldn't want to kill performance just to get SELECT FOR UPDATE.

-dain

On Feb 21, 2008, at 2:18 PM, Patrick Linskey wrote:

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 <[EMAIL PROTECTED]> wrote:
If you want pessimistic locks in OpenJPA, you'



On Thu, Feb 21, 2008 at 1:53 PM, Evan Ireland <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED]
Sent: Friday, 22 February 2008 9:50 a.m.
To: [email protected]
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

Reply via email to