entity EJB concurrent access

Discussion in 'Java' started by emte@op.pl, Aug 20, 2006.

  1. Guest

    Hi!
    This is my piece of code that doesn't work and I have no idea why:

    //this is a method in a message driven bean
    myMethod()
    {
    MyEntity myEntity = manager.find(MyEntity.class, objektId);
    manager.lock(myEntity,LockModeType.WRITE);

    if (myEntity.getStatus()==Consts.OPEN)
    {
    myEntity.setStatus(Consts.SOMETHING);
    manager.persist(myEntity);
    manager.flush();
    [...]
    }
    }

    I have a second message driven bean with similar method invoked on the
    same entity. When they are invoked at the same time I get these errors:


    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.4 (Build
    060412)): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: org.postgresql.util.PSQLException: ERROR: could not
    serialize access due to concurrent updateError Code: 0
    Call:UPDATE MyEntity SET status = ?, version = ? WHERE ((id = ?) AND
    (version = ?))
    bind => [3, 118, 258, 117]
    etc.

    I don't understand why manager.lock doesn't prevent that. I have no
    other methods accessing this table.
    Secondly, why don't I get OptimisticErrorException?
    Thirdly, what is a "good" semantics of dealing with concurrent access
    (I can't avoid concurrent access, and because these methods are invoked
    from a message bean it is essential that they complete successfuly.
    Otherwise noone would know that something went wrong - except for logs
    :) How can I retry my method?)

    My software is
    - Sun Java Application Server 9.0
    - PostgreSQL 8.1
    - Windows XP

    Thanks in advance
    Marcin
    , Aug 20, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve
    Replies:
    1
    Views:
    686
    John C. Bollinger
    Jul 15, 2003
  2. Pep
    Replies:
    6
    Views:
    811
  3. Samuel van Laere

    Entity Name or Entity Number?

    Samuel van Laere, Feb 24, 2007, in forum: HTML
    Replies:
    4
    Views:
    1,599
    Jukka K. Korpela
    Feb 24, 2007
  4. markla
    Replies:
    1
    Views:
    533
    Steven Cheng
    Oct 6, 2008
  5. Raymond Schanks
    Replies:
    0
    Views:
    645
    Raymond Schanks
    Aug 3, 2010
Loading...

Share This Page