entity EJB concurrent access

E

emte

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top